
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Display resultant array based on the object’s order determined by the first array in JavaScript?
Let’s say the following is our object −
var lastName ={ "John":"Smith", "David":"Miller", "Bob":"Taylor" }
Following is our array −
var firstName=[ "Bob", "John", "David" ]
Display resultant array based on the object’s order determined by the first array, use map(). Following is the code −
Example
var firstName=[ "Bob", "John", "David" ] var lastName ={ "John":"Smith", "David":"Miller", "Bob":"Taylor" } var values = firstName.map(getValues => lastName[getValues]); console.log(values);
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo168.js. This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo168.js [ 'Taylor', 'Smith', 'Miller' ]
- Related Articles
- Sort object array based on another array of keys - JavaScript
- Filter an object based on an array JavaScript
- Order an array of words based on another array of words JavaScript
- Manipulate Object to group based on Array Object List in JavaScript
- Splitting an array based on its first value - JavaScript
- Sort array based on another array in JavaScript
- Filter array based on another array in JavaScript
- Sorting Array based on another array JavaScript
- Filter the properties of an object based on an array and get the filtered object JavaScript
- Modify an array based on another array JavaScript
- map() array of object titles into a new array based on other property value JavaScript
- Reorder array based on condition in JavaScript?
- Build maximum array based on a 2-D array - JavaScript
- Shuffling string based on an array in JavaScript
- Group by JavaScript Array Object

Advertisements