Array Operations in Javascript: In this post we will see how to add element in an array using push() and unshift() method. And also we will remove element from an array using pop() and shift() methods.
// Add element in array
const friends = ['a', 'b', 'c', 'd', 'e'];
console.log(friends);
console.log(friends.length);
// Push element in array..
const newLength = friends.push('ram');
console.log(friends);
console.log(newLength);
// unshift element
friends.unshift('shyam');
console.log(friends);
//Remove element from Array...
friends.pop();
console.log(friends);
friends.shift();
console.log(friends);
// Find Index Number of element..
console.log(friends.indexOf('b'));
//Find element not in array
console.log(friends.indexOf('n'));
// Find element using includes() in Js
console.log(friends.includes('c'));
console.log(friends.includes('n'));
// Using icludes in condtion if..else
if (friends.includes('c')) {
console.log(`C is Avaialable in list`);
}
0 comments
Post a Comment