I have taken a word and split it into an array. Now, I am trying to divide that array into 3 separate objects like this:
Input:
var input = "7RD FLOOR, PAVE AVENUE BUILDING, DUNG STREET, 48 JUNG-GU, SEOUL 100-203"
Desired Output:
let addresses = {
address1: 7RD FLOOR, ... (must be less than 35 characters and words cannot be truncated)
address2: BUILDING, DUNG STREET ... (must be less than 35 characters and words cannot be truncated)
address3: 48 JUNG-GU ..... (the rest of the input array)
}
Current Attempt:
let addresses = response.address.split(" ");
var i;
var counterDump = 1;
addressSplitDump['address'+counterDump] = [];
for (i = 0; i < addresses.length; i++) {
if (addressSplitDump['address'+counterDump].join(' ').length <= 35) {
addressSplitDump['address'+counterDump].push(addresses[0]);
let sliceAddress = addresses.shift();
} else if (counterDump == 3 ) {
addressSplitDump['address'+counterDump] = addresses;
} else {
counterDump++;
}
}