How does Js delete an element in an array?

get a string of arrays as follows:

var data = [
{"id":"1","name":"","age":"25"},
{"id":"2","name":"","age":"24"},
{"id":"3","name":"","age":"27"},
{"id":"4","name":"","age":"24"},
{"id":"5","name":"","age":"22"},
];

Delete the people whose age is less than or equal to 25 years old in the array, and return the new array as follows:

var data = [
{"id":"1","name":"","age":"25"},
{"id":"3","name":"","age":"27"},
];
Feb.26,2021

filter learn


Thank you, first floor

var data = [ 
    {"id":"1","name":"","age":"25"},
    {"id":"2","name":"","age":"24"},
    {"id":"3","name":"","age":"27"},
    {"id":"4","name":"","age":"24"},
    {"id":"5","name":"","age":"22"},

];

new_data = data.filter(function(element, index) {
    return element['age'] >= 25; 
});

console.log(new_data);

var data = [
        {"id":"1","name":"","age":"25"},
        {"id":"2","name":"","age":"24"},
        {"id":"3","name":"","age":"27"},
        {"id":"4","name":"","age":"24"},
        {"id":"5","name":"","age":"22"},
    ];

    var data1 = []
    data.filter(function(e){
        if(e.age > 25){
            data1.push(e)
        }
    })
    console.log(data1)   //{id: "3", name: "", age: "27"}

var data = [
            { "id": "1", "name": "", "age": "25" },
            { "id": "2", "name": "", "age": "24" },
            { "id": "3", "name": "", "age": "27" },
            { "id": "4", "name": "", "age": "24" },
            { "id": "5", "name": "", "age": "22" },
        ];

    var newData= data.filter(v=>v.age >= 25)

Delete less than or equal to 25, and return a new array

function splice(){
    for(let i = 0;i<data.length;iPP){
        if(parseInt(data[i].age)<26){
            data.splice(i,1);
            i--;
        }
    }
    console.log(data);
}

var data = [
            { "id": "1", "name": "", "age": "25" },
            { "id": "2", "name": "", "age": "24" },
            { "id": "3", "name": "", "age": "27" },
            { "id": "4", "name": "", "age": "24" },
            { "id": "5", "name": "", "age": "22" },
        ];

    var newData= [];
    var res = data.forEach(function (item, index, input) {
            if (parseInt(item["age"]) >= 25){
                newData.push(item);
            }
        })
    console.log(newData);

using underscore.js 's filter can solve this problem:

var data = [
            { "id": "1", "name": "", "age": "25" },
            { "id": "2", "name": "", "age": "24" },
            { "id": "3", "name": "", "age": "27" },
            { "id": "4", "name": "", "age": "24" },
            { "id": "5", "name": "", "age": "22" },
        ];
        var newData = _.filter(data, function(d){ return d.age > 25; })
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-1bde46f-3092e.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-1bde46f-3092e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?