I am a beginner and getting confused about this. I am trying to insert brackets '['and ']' into the 'text' array below in order to make an array of arrays and am unable to figure it out. Can anyone please advise? Thank you all.
var text = [
1,
2, 3,
4, 5, 6,
]
should become
var text = [
[1],
[2, 3],
[4, 5, 6],
]
I found this from a previous Stack thread but am not sure how to implement it thought I think it is one possible method for attacking this:
String.prototype.insert = function (index, string) {
if (index > 0)
return this.substring(0, index) + string + this.substring(index, this.length);
else
return string + this;
};
// var something = "How you?";
// something = something.insert(3, " are");
Aucun commentaire:
Enregistrer un commentaire