What is the problem with js looping objects? Solve.

var rawDataList = 
[
    {
        "countDate": "2018-04-08",
        "countNum": "5"
    },
    {
        "countDate": "2018-04-18",
        "countNum": "2"
    },
    {
        "countDate": "2018-04-23",
        "countNum": "7"
    }
 ]

how can an json array like this delete an item based on the value of countNum and return a new array?

Apr.07,2021

Filter is available through array filter ();

var rawDataList = 
[
    {
        "countDate": "2018-04-08",
        "countNum": "5"
    },
    {
        "countDate": "2018-04-18",
        "countNum": "2"
    },
    {
        "countDate": "2018-04-23",
        "countNum": "7"
    }
 ]
rawDataList = rawDataList.filter(i=>i.countNum!=="7")

Note that the value of your countNum is of type string.


const newDataList = rawDataList.filter(item => {
   return item.countNum !== value;
})

can take a look at the use of filter.


for example, if you want to delete an item with a value of 2 for countNum

var countValue = 2;    // 
var newArray= rawDataList .filter(function(item){ return item.countNum!= countValue });

newArray is the new array you need

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f259-2c463.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f259-2c463.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?