“Método de filtro JavaScript” Código de respuesta

Filtrar 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

Filtrar matriz de javascript

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

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

console.log(result);
White Browed Owl

Filtro de objetos de 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

Cómo funciona la función filtre () 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

Método de filtro 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

Respuestas similares a “Método de filtro JavaScript”

Preguntas similares a “Método de filtro JavaScript”

Más respuestas relacionadas con “Método de filtro JavaScript” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código