Basic CRUD Array Operations in JavaScript

Sometimes it pays just to stick to the basics. Here are CRUD operations for a basic array:

1. Create an element to the end of an array

let clubs = ['baseball','running','computer club'];
clubs.push('tennis');

console.log(clubs);

2. Delete an element from the end of an array

let clubs = ['baseball','running','computer club'];
const lastElement = seas.pop();
console.log(lastElement);

3. Reading an index from an element in an array

let clubs = ['baseball','running','computer club'];
let index = clubs.indexOf("running");
console.log(index);

4. Update an index from an element in an array

let clubs = ['baseball','running','computer club'];
clubs.splice(1, 0, 'tennis');
console.log(clubs);

Leave a Reply

Your email address will not be published. Required fields are marked *