对象已移动

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

Huawei Cloud rolls out Pangu Models 5.5 to cover more industries
Softwares

Huawei Cloud rolls out Pangu Models 5.5 to cover more industries

by admin
June 24, 2025
Minor update(4) for Vivaldi Android Browser 7.4
Softwares

Minor update(4) for Vivaldi Android Browser 7.4

by admin
June 21, 2025
How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025
Softwares

How AI Medical Coding Software Reduces Errors & Accelerates Billing in 2025

by admin
June 22, 2025
10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy
Softwares

10+ Best Free Portfolio & Lookbook Templates for InDesign in 2025 — Speckyboy

by admin
June 20, 2025
User Guide For CS-Cart Product Search By Barcode
Softwares

User Guide For CS-Cart Product Search By Barcode

by admin
June 18, 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
Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

Pamela Anderson raves about new natural, makeup-free look: ‘It’s freedom’

October 8, 2023
Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

Alec Baldwin indicted again for ‘Rust’ shooting that left cinematographer dead – National

January 21, 2024
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

A look into CAMPUS, ShopBack’s new Singapore HQ at Pasir Panjang

July 2, 2022
Guide for Bagisto Quick Commerce

Guide for Bagisto Quick Commerce

October 16, 2024
User Manual for Odoo Docx Report Builder

User Manual for Odoo Docx Report Builder

November 30, 2024
Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

Aaron Rodgers returns to ‘Pat McAfee Show’ 1 day after being axed by host – National

January 11, 2024
8BitDo Retro Mechanical Keyboard C64 Review

8BitDo Retro Mechanical Keyboard C64 Review

March 24, 2025
Over 140 People ‘Pricked’ With Syringes at Music Festival

Over 140 People ‘Pricked’ With Syringes at Music Festival

June 24, 2025
Samsung Galaxy Watch 8 Classic: Battery, Design, and More

Samsung Galaxy Watch 8 Classic: Battery, Design, and More

June 24, 2025
Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+

Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+

June 24, 2025
Cobra Kai star Martin Kove ‘kicked out of fan convention’ after allegedly ‘biting’ co-star Alicia Hannah-Kim

Cobra Kai star Martin Kove ‘kicked out of fan convention’ after allegedly ‘biting’ co-star Alicia Hannah-Kim

June 24, 2025
Liam Neeson Drives a Bus to Escape Himalayan Kidnappers in Trailer For ICE ROAD: VENGEANCE — GeekTyrant

Liam Neeson Drives a Bus to Escape Himalayan Kidnappers in Trailer For ICE ROAD: VENGEANCE — GeekTyrant

June 24, 2025
X Adds More Sports Engagement Options To Maintain Community Engagement

X Adds More Sports Engagement Options To Maintain Community Engagement

June 24, 2025
Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

Maroon 5’s New Album ‘Love Is Like’ Release Date, Tour Dates Announced

June 23, 2025
Google adds AI features to Chromebook Plus devices

Google adds AI features to Chromebook Plus devices

June 23, 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

  • Over 140 People ‘Pricked’ With Syringes at Music Festival
  • Samsung Galaxy Watch 8 Classic: Battery, Design, and More
  • Shane Gillis Set As Host Of The 2025 ESPYS For ABC & ESPN+
  • 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