javascript - remove array element on condition

后端 未结 7 818
北荒
北荒 2020-11-29 05:39

I was wondering how I\'d go about implementing a method in javascript that removes all elements of an array that clear a certain condition. (Preferably without using jQuery)

7条回答
  •  我在风中等你
    2020-11-29 06:11

    You can use Array filter method.

    The code would look like this:

    ar = [1, 2, 3, 4];
    ar = ar.filter(item => !(item > 3));
    console.log(ar) // [1, 2, 3]

提交回复
热议问题