“trouver dans js” Réponses codées

Trouver le tableau javascript

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

trouver javascript

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

trouver dans 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

trouver dans js

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

trouver dans 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

Réponses similaires à “trouver dans js”

Questions similaires à “trouver dans js”

Plus de réponses similaires à “trouver dans js” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code