“Encontre em JS” Respostas de código

Encontre JavaScript de Array

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Energetic Eland

JavaScript Find

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'cherries', quantity: 8}
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
  {name: 'cherries', quantity: 15}
  
];

const result = inventory.find( ({ name }) => name === 'cherries' );

console.log(result) // { name: 'cherries', quantity: 5 }
Real Rattlesnake

JavaScript Array.find

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Amused Albatross

Encontre em JS

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

function isCherries(fruit) {
  return fruit.name === 'cherries';
}

console.log(inventory.find(isCherries)); // { name: 'cherries', quantity: 5 }

/* find মেথড অলওয়েজ অ্যারের সরাসরি ভ্যালু রিটার্ণ করে। 
অর্থাৎ কন্ডিশনের সাথে মিলে যাওয়ার পরে যে কারণে মিলসে সেই লজিক অনুযায়ী 
ঐ অ্যারে থেকে প্রথম ভ্যালুটা রিটার্ণ করে। সে কারণে এখানে অ্যারের পুরো ভ্যালুটা আউটপুট হিসেবে দেখাচ্ছে। */

// Same Code Using Arrow function & destructuring technique

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

const result = inventory.find( ({ name }) => name === 'cherries' );   // ({name})==> destructuring technique

console.log(result); // { name: 'cherries', quantity: 5 }
Ainul Sakib

Encontre em JS

The first element that will be found by that function
const f = array1.find(e => e > 10);
EON

Encontre em JS

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

function isCherries(fruit) {
  return fruit.name === 'cherries';
}

console.log(inventory.find(isCherries));
// { name: 'cherries', quantity: 5 }
Shan Thiru

Respostas semelhantes a “Encontre em JS”

Perguntas semelhantes a “Encontre em JS”

Mais respostas relacionadas para “Encontre em JS” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código