
- 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
Finding the nth power of array element present at nth index using JavaScript
Problem
We are required to write a JavaScript function that takes in an array of numbers. Our function should map the input array to another array in which each element is raised to its 0-based index.
And finally, our function should return this new array.
Example
Following is the code −
const arr = [5, 2, 3, 7, 6, 2]; const findNthPower = (arr = []) => { const res = []; for(let i = 0; i < arr.length; i++){ const el = arr[i]; const curr = Math.pow(el, i); res[i] = curr; }; return res; }; console.log(findNthPower(arr));
Output
[ 1, 2, 9, 343, 1296, 32 ]
- Related Articles
- Finding nth element of the Padovan sequence using JavaScript
- Finding nth element of an increasing sequence using JavaScript
- Finding sum of every nth element of array in JavaScript
- Finding the nth element of the lucas number sequence in JavaScript
- Finding the nth missing number from an array JavaScript
- MongoDB query on nth element (variable index) of subdocument array
- Returning the value of nth power of iota(i) using JavaScript
- Finding the nth digit of natural numbers JavaScript
- Finding the nth prime number in JavaScript
- Nth element of the Fibonacci series JavaScript
- Reduce an array to the sum of every nth element - JavaScript
- Get the index of the nth item of a type in a JavaScript array
- Finding nth digit of natural numbers sequence in JavaScript
- Finding the nth day from today - JavaScript (JS Date)
- How to remove every Nth element from an array JavaScript?

Advertisements