Answers for "js insert"

13

javascript push in specific index

arr.splice(index, 0, item);
//explanation:
inserts "item" at the specified "index",
deleting 0 other items before it
Posted by: Guest on July-16-2020
21

javascript insert item into array

var colors=["red","blue"];
var index=1;

//insert "white" at index 1
colors.splice(index, 0, "white");   //colors =  ["red", "white", "blue"]
Posted by: Guest on July-22-2019
2

js add

//HOW TO ADD:
var num1 = 4;
var num2 = 6;
var answer = 4 + 6; //You can do num1 + num2 here!
function add(num1, num2) {
  return num1 + num2;
};
console.log("4 + 6 is: " + add());
console.log("I hope this helped!");
Posted by: Guest on June-21-2020
1

js insert

arr.splice(index, 0, item); 
// will insert item into arr at the specified index 
// (deleting 0 items first, that is, it's just an insert).
Posted by: Guest on May-15-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language