Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 6553

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T07:35:08+00:00 2024-11-27T07:35:08+00:00

Underrated JavaScript Array Methods – Part 2

  • 60k

Alt Text

Last week, we looked at a few JavaScript Array Methods which you can read about in my last article: Underrated JavaScript Array Methods – Part 1. We are rounding up this week with a few more methods.

– flat()

This method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

Syntax – array.flat(depth?)

Note: Arguments followed by a question mark are optional.

const array = [ [1, 2], [3, 4], [[5, 6]] ];  const flattenedOnce = array.flat(); const flattenedTwice = array.flat(2);  console.log(flattenedOnce); // expected output: Array [1, 2, 3, 4, [5, 6]]  console.log(flattenedTwice); // expected output: Array [1, 2, 3, 4, 5, 6] 
Enter fullscreen mode Exit fullscreen mode

– reduceRight()

The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value. This method comes in pretty handy when you want to specify items in a left-to-right manner but execute them in a right-to-left manner.

You could use reduceRight() method to replace Array.reverse().reduce()

const numbers = [[0, 0], [1, 1], [2, 2]];  const modifiedNumbers = numbers.reduceRight( (a, b) => a.concat(b) );  console.log(modifiedNumbers); // expected output: Array [2, 2, 1, 1, 0, 0] 
Enter fullscreen mode Exit fullscreen mode

– lastIndexOf()

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex if this argument is available. The lastIndexOf() method is case-sensitive.

Syntax – array.lastIndexOf(searchValue, fromIndex?)

const names = ['John', 'Bolanle', 'Dwight', 'Mary'];  console.log( names.lastIndexOf('Dwight') ); // expected output: 2  // -1 is returned if the searchValue is absent in the Array  console.log( names.lastIndexOf('Tiger') ); // expected output: -1 
Enter fullscreen mode Exit fullscreen mode

See you next week 💙

beginnersjavascriptwebdev
  • 0 0 Answers
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.