Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript filter method

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Using Javascript Filter Method</title>
</head>
<body>
    <h1 id="demo"></h1>

    <!-- <script src="index.js"></script> -->

    <script>
        const person = [ 
    {name:"fredrick",
        "id":1,
    },

    {name:"sarah",
        "id":2
    },
    {name:"favour",
        "id":3
    },
    {name:"abraham",
        "id":4
    },
    {name:"isaac",
        "id":5
    },

    {name:"esther",
        "id":6
    }
]

let sortedPerson = person
sortedPerson = sortedPerson.filter(item => {
if (item.name === "fredrick" ){
    return true

    }

})
    console.log(sortedPerson)

  
    </script>
</body>
</html>
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #filter #method
ADD COMMENT
Topic
Name
7+5 =