Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Array.find Shorthand javascript

// Array.find Shorthand javascript
// Longhand:
const pets = [
  { type: 'Dog', name: 'Max'},
  { type: 'Cat', name: 'Karl'},
  { type: 'Dog', name: 'Tommy'},
]

function findDog(name) {
  for(let i = 0; i<pets.length; i++) {
    if(pets[i].type === 'Dog' && pets[i].name === name) {
      return pets[i];
    }
  }
}
console.log(findDog("Tommy")); // { type: 'Dog', name: 'Tommy' }


// Shorthand:
const findDog_ = pets.find(pet => pet.type ==='Dog' && pet.name === 'Tommy');
console.log(findDog_); // { type: 'Dog', name: 'Tommy' }
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get html paramater in js 
Javascript :: lement.style { } 
Javascript :: reactRender 
Javascript :: react js practical tutorial 
Javascript :: different way to for loop js 
Javascript :: alert(document.cookie); 
Javascript :: rxjs: from usage 
Javascript :: java script names starting with b foreach 
Javascript :: loose and strict equality 
Javascript :: One component overlapping on other in react.js app 
Javascript :: convert online code javascript to python 
Javascript :: replace for ifelse 
Javascript :: provider._web3Provide.sendAsync as any 
Javascript :: custu, loading next js 
Javascript :: function directory javascript 
Javascript :: request body goes undefined in nodejs mongodb 
Javascript :: Here is an example of loading a series of middleware functions at a mount point, with a mount path. It illustrates a middleware sub-stack that prints request info for any type of HTTP request to the /user/:id path. 
Javascript :: indexable values js 
Javascript :: javascript intersection recursion 
Javascript :: typeorm not supporrtted insert large data 
Javascript :: js set to array casting 
Javascript :: stdi nodejs 
Javascript :: build an javascript URL and its search parameters 
Javascript :: Spread syntax in ES6 
Javascript :: invert binary tree js 
Javascript :: iteration methods 
Javascript :: javascript slider elementor 
Javascript :: programmatically change mongoose schema enum values 
Javascript :: how to prevent todos from vanishing after refreshing page - javascript 
Javascript :: datatables show loading 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =