how to modify arrya in place javascript code example
Example 1: 6 ways to modify an array javascript
let browsers = ['chrome', 'firefox', 'edge'];
browsers.unshift('safari');
console.log(browsers);
let browsers = ['chrome', 'firefox', 'edge'];
browsers.push('safari');
console.log(browsers);
let browsers = ['chrome', 'firefox', 'edge'];
browsers.shift();
console.log(browsers);
let browsers = ['chrome', 'firefox', 'edge'];
browsers.pop();
console.log(browsers);
var fruits = ["Banana", "Orange", "Apple", "Mango"];
function myFunction() {
fruits.splice(3, 0, "Lemon", "Kiwi");
document.getElementById("demo").innerHTML = fruits;
}
var fruits = ["Banana", "Orange", "Apple", "Mango"];
function myFunction() {
fruits.splice(2, 1);
document.getElementById("demo").innerHTML = fruits;
}
Example 2: how to modify an array
let schedule = ['I', 'have', 'a', 'meeting', 'tommorrow'];
schedule.splice(0, 4, 'we', 'are', 'going', 'to', 'swim');
console.log(schedule);