What is push method in javascript?
Javascript array push method:
push(): means it's add value one or multiple in the our array from the last index and return with new index.
Javascript push() example:
<script>
const colors = ['Red', 'Green', 'blue'];
const colorCount = colors.push('Black');
console.log(colorCount);
// expected output: 4
console.log(colors);
// ["Red", "Green", "blue", "Black"]
colors.push('Orange', 'White', 'Coffee');
console.log(colors);
// ["Red", "Green", "blue", "Black", "Orange", "White", "Coffee"]
</script>
No comments:
Note: Only a member of this blog may post a comment.