DEV Community

Abraham Alanya
Abraham Alanya

Posted on

1

Recorrer un array en Javascript

let articulos = [
 {nombre: "a", precio: 300},
 {nombre: "b", precio: 3100},
 {nombre: "c", precio: 2300},
 {nombre: "d", precio: 200},
 {nombre: "e", precio: 100},
 {nombre: "f", precio: 400},
 {nombre: "g", precio: 3500},
 {nombre: "h", precio: 1300},
 {nombre: "i", precio: 2300},
];
Enter fullscreen mode Exit fullscreen mode

filter()

Crea un nuevo array con los elementos que cumplan el parΓ‘metro definido.

let filtrar = articulos.filter(function (articulo) {
 return articulo.precio <= 1000;
});
Enter fullscreen mode Exit fullscreen mode

map()

let nombre = articulos.map(function (articulo){
 return articulo.nombre;
});
Enter fullscreen mode Exit fullscreen mode

find()

let busqueda = articulos.find(function(articulo){
 return articulo.nombre === "g";
});
Enter fullscreen mode Exit fullscreen mode

foreach()

articulos.forEach(function(articulo){
 console.log(articulo.nombre);
});
Enter fullscreen mode Exit fullscreen mode

some()

Devuelve true y false

let barato = articulos.some(function(articulo){
 return articulo.precio <= 1000;
})
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Auth0

Easy to implement, endless possibilities

With a few lines of code, you can have Auth0 by Okta integrated in any app written in any language and any framework. πŸš€ Start building for free today.

Sign up now

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay