delete Operator don’t impact the length of Array in JavaScript


/ Published in: JavaScript
Save to your folder(s)

delete Operator don’t impact the length of Array in JavaScript


Copy this code and paste it in your HTML
  1. Ref: https://techfiddler.wordpress.com/2015/06/02/delete-operator-dont-impact-the-length-of-array-in-javascript/
  2.  
  3.  
  4.  
  5. var fruits = ["Apple" , "Banana", "Grape", "Litchi", "Mango", "Orange"];
  6.  
  7. console.log(fruits.length); //prints 6 as there are six elements
  8. console.log(fruits[3]); //prints Litchi
  9. delete fruits[3];
  10. console.log(fruits.length); //still prints 6
  11. console.log(fruits[3]); //prints undefined

URL: https://techfiddler.wordpress.com/2015/06/02/delete-operator-dont-impact-the-length-of-array-in-javascript/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.