How to remove item of a array in js

  1. use splice method
    It can also be used to replace/delete/add one or more values in an array.
    index: from which itme to replace/delete
    len: Length of substitution/deletion
    item:the replace value, empty if delete

var arr = ['a','b','c','d']
arr.splice(1,1)   //['a','c','d']
arr.splice(1,2)  //['a','d']
  1. use delete  method
    The length of array won't be changed. The delete item would be undefined

var arr = ['a','b','c','d']
delete arr[1]  //['a', ,'c','d']
date2019-04-17 23:56:07 Author:JPH
Related Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *