[Solved] javascript array.Join continious srings values into new array


I’ve modified what you already have to make it work. whenever you get a number, you push the concatenated string that you found before that number and then push the number. the if condition after the for loop is to check if you have more strings after the last number is pushed.

var s = "";
var new_data = []
var pin = ["john", "mike", "george", 55, "hello", 344, "goodmorning"]

for (let i = 0; i < pin.length; i++) {
  if (typeof pin[i] === "string") {
    s = s + pin[i]
  } else {
    if (s !== "") {
      new_data.push(s);
      s = "";
    }
    new_data.push(pin[i])
  }
}
if (s !== "") {
  new_data.push(s);
}

console.log(new_data)

solved javascript array.Join continious srings values into new array