Truncate JavaScript array using length

Here are few examples to truncate JavaScript array using length property

var chars = ["a", "w", "r", "t", "y", "y"];
console.log(chars); // ["a", "w", "r", "t", "y", "y"];
chars.length = 2; 
console.log(chars); // ["a", "w"];

chars.length = 0;
console.log(chars); // [];

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails