#javascriptInputOutput
Javascript Trick :2

#javascriptInputOutput

to empty an array in JavaScript?

let var arrayList = ['a', 'b', 'c', 'd', 'e', 'f'];

Method 1:-

arrayList = [];        

This is the most easiest way to make an empty array.

Just assign a blank array .

Method 2:-

arrayList.length = 0;        

If you make array length to zero using inbuild length function of JavaScript then you can get empty array .

If you want in details please visit my previous article .

Method 3:-

arrayList.splice(0, arrayList.length);        

You can use also splice method to blank an array . so the first element of this method is the position to remove items index and the last one is how many number of items to be removed.

Here the start index is zero and number of items are array length, it means all elements of an array .

要查看或添加评论,请登录

Abhisek Mati的更多文章

  • #javascriptInputOutput

    #javascriptInputOutput

    What will be the output ? (function(){ ? ? var a=5; ? ? ?var b=5; })(); console.log(b); Output will be an error (b is…

  • JavaScript Trick:1

    JavaScript Trick:1

    #javascriptInputOutput let arr=[1,2,3,4,5]; arr.length=0; console.

社区洞察

其他会员也浏览了