“Metode filter JavaScript” Kode Jawaban

Filter JavaScript

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length < 6);

console.log(result);

//OUTPUT: ['spray', 'limit', 'elite']
Moscode

Filter JavaScript Array

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
White Browed Owl

Filter Objek JavaScript

function objectFilter = (obj, predicate) => 
    Object.keys(obj)
          .filter( key => predicate(obj[key]) )
          .reduce( (res, key) => (res[key] = obj[key], res), {} );

// Example use:
var scores = {
    John: 2, Sarah: 3, Janet: 1
};

var filtered = objectFilter(scores, num => num > 1); 
console.log(filtered);
QuietHumility

.Filter JS

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length > 6);

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
Difficult Dolphin

Bagaimana fungsi filter () bekerja javascript

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]
DCmax1k

Metode filter JavaScript

<!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>
Fredrick Idemudia

Jawaban yang mirip dengan “Metode filter JavaScript”

Pertanyaan yang mirip dengan “Metode filter JavaScript”

Lebih banyak jawaban terkait untuk “Metode filter JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya