对象已移动

可在此处找到该文档 JavaScript Array Methods: find() [Article] – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

JavaScript Array Methods: find() [Article]

by admin
3 years ago
in Softwares
JavaScript Array Methods: find() [Article]
Share on FacebookShare on Twitter


Ever wanted to seek out or find a particular array merchandise? Fortunately for us, we’ve got a JavaScript methodology that may deal with that activity with ease. On this fast information, I’ll go over the discover() JavaScript array methodology. In the event you’re prepared, let’s get into it!

Lets begin with the MDN documentation:

MDN – discover()
The discover() methodology returns the primary ingredient within the offered array that satisfies the offered testing perform. If no values fulfill the testing perform, undefined is returned.

In keeping with the documentation, it seems to be like discover() returns the primary occasion of our logic that’s truthy. Let’s checkout some examples.

Think about the next array:

const numbers = [10, 20, 30, 40, 50]

Let’s say we wished to discover the primary worth on this array that’s higher than 25. We are able to do this fairly just by writing the next:

numbers.discover(num => num > 25)

This may return the very first merchandise that’s higher than 25. So 30 shall be returned. This methodology can even discover strings! Verify this out:

const customers = ['Alex', 'Taylor', 'Jamie']

console.log( customers.discover(person => person === 'Taylor') );

//anticipated output: 'Taylor'

As you’ll be able to see, it is a fairly straightforward methodology to make use of and may also help you find particular array gadgets simply. Usually you’ll additionally wish to pair this with the indexOf methodology or use the index parameter you’ve got entry to to retrieve the index of the returned array merchandise. I’ll present an instance beneath of each however if you happen to’d wish to study extra in regards to the indexOf array methodology, I’ll hyperlink beneath some assets.

JavaScript Fundamental Array Strategies – Weblog
JavaScript Fundamental Array Strategies – Video

Think about the next array:

const college students = ['Brian', 'Rohald', 'Travis']

Let’s say we wished to seek out out if “Rohald” is a pupil and if that’s the case, we wish to get again the array index that his identify falls into. We are able to write the next:

const selectedStudent = college students.discover(pupil => pupil === 'Rohald');
console.log(college students.indexOf(selectedStudent))

//anticipated output: 1

Now, right here is identical instance however utilizing the index parameter:

const college students = ['Brian', 'Rohald', 'Travis']

const selectedStudent = college students.discover((pupil, index) => {
    if (pupil === 'Travis') {
        console.log(index)
    }
})

Superior, now it’s best to know the best way to use the discover() methodology in your initiatives. I hope you’ll be able to really feel comfy utilizing this methodology going ahead as a result of it is going to absolutely pace up your workflow!

Till subsequent time, have enjoyable and completely happy coding!



Source link

Tags: arrayArticleFindJavaScriptMethods
Previous Post

Ashton Kutcher’s Brutally Honest Conversation With His Twin Brother

Next Post

YouTube Adds Chat Emotes, New Shorts Editing Tools and Automated Audio Dubbing in Other Languages

Related Posts

JFrog finds MCP-related vulnerability, highlighting need for stronger focus on security in MCP ecosystem
Softwares

JFrog finds MCP-related vulnerability, highlighting need for stronger focus on security in MCP ecosystem

by admin
July 13, 2025
Meta and UK Government launch ‘Open Source AI Fellowship’
Softwares

Meta and UK Government launch ‘Open Source AI Fellowship’

by admin
July 12, 2025
User Guide for Odoo Zkteco Device Integration
Softwares

User Guide for Odoo Zkteco Device Integration

by admin
July 15, 2025
Supervised vs Unsupervised Learning: Machine Learning Overview
Softwares

Supervised vs Unsupervised Learning: Machine Learning Overview

by admin
July 10, 2025
Minor update (2) for Vivaldi Desktop Browser 7.5
Softwares

Minor update (2) for Vivaldi Desktop Browser 7.5

by admin
July 9, 2025
Next Post
YouTube Adds Chat Emotes, New Shorts Editing Tools and Automated Audio Dubbing in Other Languages

YouTube Adds Chat Emotes, New Shorts Editing Tools and Automated Audio Dubbing in Other Languages

Lizzo’s Acceptance Speech at the 2022 PCAs

Lizzo's Acceptance Speech at the 2022 PCAs

  • Trending
  • Comments
  • Latest
Bones: All Of Brennan’s Interns, Ranked

Bones: All Of Brennan’s Interns, Ranked

June 15, 2021
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
CBackup Review: Secure and Free Online Cloud Backup Service

CBackup Review: Secure and Free Online Cloud Backup Service

September 18, 2021
A Timeline of His Relationships – Hollywood Life

A Timeline of His Relationships – Hollywood Life

December 20, 2023
Coldplay’s Chris Martin says he ‘never criticized’ Toronto’s Rogers Stadium

Coldplay’s Chris Martin says he ‘never criticized’ Toronto’s Rogers Stadium

July 13, 2025
Scrapped ‘VH III’ Sequel Had ‘Really Good’ Songs

Scrapped ‘VH III’ Sequel Had ‘Really Good’ Songs

March 23, 2023
Get to Know Ronnie Shacklett – Hollywood Life

Get to Know Ronnie Shacklett – Hollywood Life

December 6, 2023
How to Build a DIY Spotify Music Player with Raspberry Pi Pico

How to Build a DIY Spotify Music Player with Raspberry Pi Pico

May 13, 2025
Zafro 16,000 BTU portable air conditioner review – Can it beat the Texas heat?

Zafro 16,000 BTU portable air conditioner review – Can it beat the Texas heat?

July 16, 2025
Dax Shepard Shares Kristen Bell Nude Photo Amid Emmys Nod

Dax Shepard Shares Kristen Bell Nude Photo Amid Emmys Nod

July 16, 2025
Katherine Schwarzenegger’s drastic measures for step-parenting with Chris Pratt

Katherine Schwarzenegger’s drastic measures for step-parenting with Chris Pratt

July 16, 2025
X Shares Key Data on Holiday Season Planning [Infographic]

X Shares Key Data on Holiday Season Planning [Infographic]

July 16, 2025
The 10 Biggest Superhero Movie Opening Weekends Ever

The 10 Biggest Superhero Movie Opening Weekends Ever

July 16, 2025
X and Los Lobos: Celebrating ‘99 Years of Rock n’ Roll’ Together

X and Los Lobos: Celebrating ‘99 Years of Rock n’ Roll’ Together

July 15, 2025
Samsung Galaxy G Fold: Features, Price, and More

Samsung Galaxy G Fold: Features, Price, and More

July 15, 2025
2025 Emmy Nominations: The Complete List

2025 Emmy Nominations: The Complete List

July 15, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Zafro 16,000 BTU portable air conditioner review – Can it beat the Texas heat?
  • Dax Shepard Shares Kristen Bell Nude Photo Amid Emmys Nod
  • Katherine Schwarzenegger’s drastic measures for step-parenting with Chris Pratt
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life