Append something to an array?

In this tutorial learn how to append something(string/number/value) to an array, can append value in array using push() function,

// initialize array
var arr = [
  "Jack",
  "Taylor",
  "Jhone"
];

// append new value to the array
arr.push("Huge");

console.log(arr);



You can  append more than one value to an array in a single call  use the push() function

// initialize array
var arr = ["Student", "Teacher", "Principal", "Mam"];

// append multiple values to the array
arr.push("Math Teacher", "IT Teacher");

// display all values
for (var i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}



No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...