对象已移动

可在此处找到该文档 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

How to Be the Leader Your Web Design Clients Need — Speckyboy
Softwares

How to Be the Leader Your Web Design Clients Need — Speckyboy

by admin
August 4, 2025
New tool offers direct lighting control for photographs using 3D scene modeling
Softwares

New tool offers direct lighting control for photographs using 3D scene modeling

by admin
August 3, 2025
Laravel ONDC Connector – Webkul Blog
Softwares

Laravel ONDC Connector – Webkul Blog

by admin
August 2, 2025
Custom search engine – Vivaldi iOS Browser snapshot 3767.4
Softwares

Custom search engine – Vivaldi iOS Browser snapshot 3767.4

by admin
August 5, 2025
The hidden crisis behind AI’s promise: Why data quality became an afterthought
Softwares

The hidden crisis behind AI’s promise: Why data quality became an afterthought

by admin
July 31, 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
Instagram Adds New Teleprompter Tool To Edits

Instagram Adds New Teleprompter Tool To Edits

June 11, 2025
Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

Amazon Forgot to Take the 2024 MacBook Air Off Sale After Their Big Spring Event

April 4, 2025
The hidden crisis behind AI’s promise: Why data quality became an afterthought

The hidden crisis behind AI’s promise: Why data quality became an afterthought

July 31, 2025
The Ultimate Guide to Samsung Galaxy Z Flip 7

The Ultimate Guide to Samsung Galaxy Z Flip 7

August 5, 2025
TikTok Publishes Report on Top UK Product Trends

TikTok Publishes Report on Top UK Product Trends

August 3, 2025
ONyc Launches on Kamino, Unlocking Real-World Yield and Collateral Utility in Solana DeFi

ONyc Launches on Kamino, Unlocking Real-World Yield and Collateral Utility in Solana DeFi

August 5, 2025
Abbotsford, B.C., denies permit for MAGA singer

Abbotsford, B.C., denies permit for MAGA singer

August 2, 2025
Behind the scenes of Warped Tour Long Beach 2025

Behind the scenes of Warped Tour Long Beach 2025

August 1, 2025
Ozzy Osbourne’s Cause of Death Revealed

Ozzy Osbourne’s Cause of Death Revealed

August 5, 2025
ONyc Launches on Kamino, Unlocking Real-World Yield and Collateral Utility in Solana DeFi

ONyc Launches on Kamino, Unlocking Real-World Yield and Collateral Utility in Solana DeFi

August 5, 2025
Song Young-kyu, South Korean Actor, Dead at 55

Song Young-kyu, South Korean Actor, Dead at 55

August 5, 2025
The Ultimate Guide to Samsung Galaxy Z Flip 7

The Ultimate Guide to Samsung Galaxy Z Flip 7

August 5, 2025
Celebrity Deaths of 2025: Chuck Mangione, More Stars We’ve Lost

Celebrity Deaths of 2025: Chuck Mangione, More Stars We’ve Lost

August 5, 2025
A Look at Meta’s ‘Value Rules’ for Specific Ad Targeting Approaches

A Look at Meta’s ‘Value Rules’ for Specific Ad Targeting Approaches

August 5, 2025
Donald Trump Gave Prince Andrew 'A List Of Masseuses' After Gross Convo, Claims Book

Donald Trump Gave Prince Andrew 'A List Of Masseuses' After Gross Convo, Claims Book

August 5, 2025
Diddy’s Ex-Girlfriend Wants Him Released Ahead Of Sentencing

Diddy’s Ex-Girlfriend Wants Him Released Ahead Of Sentencing

August 4, 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

  • Ozzy Osbourne’s Cause of Death Revealed
  • ONyc Launches on Kamino, Unlocking Real-World Yield and Collateral Utility in Solana DeFi
  • Song Young-kyu, South Korean Actor, Dead at 55
  • 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