1arr.splice(index, 0, item);
2//explanation:
3inserts "item" at the specified "index",
4deleting 0 other items before it
1var colors=["red","blue"];
2var index=1;
3
4//insert "white" at index 1
5colors.splice(index, 0, "white"); //colors = ["red", "white", "blue"]
6
1// for me lol... pls don't delete!
2// use splice to insert element
3// arr.splice(index, numItemsToDelete, item);
4var list = ["hello", "world"];
5list.splice( 1, 0, "bye");
6//result
7["hello", "bye", "world"]
8
1const months = ['Jan', 'March', 'April', 'June'];
2months.splice(1, 0, 'Feb');
3// inserts at index 1
4console.log(months);
5// expected output: Array ["Jan", "Feb", "March", "April", "June"]
6
7months.splice(4, 1, 'May');
8// replaces 1 element at index 4
9console.log(months);
10// expected output: Array ["Jan", "Feb", "March", "April", "May"]
1var select =[2,5,8];
2var filerdata=[];
3for (var i = 0; i < select.length; i++) {
4 filerdata.push(this.state.data.find((record) => record.id == select[i]));
5}
6//I have a data which is object,
7//find method return me the filter data which are objects
8//now with the push method I can make array of objects
1
2var list = ["foo", "bar"];
3
4
5list.push("baz");
6
7
8["foo", "bar", "baz"] // result
9
10