- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To find the cubes of elements of given array we need to run a for loop to access each and every element and we need to use "=" operator to replace elements with their cubes.To get the desired values the below steps need to be followed.

1) Declared an array a = [1,2,3,4,5]

2) For loop was introduced to access each and every element in the array(a[i]).

3) Inside for loop "=" operator is used to replace the element with their cubic values(a[i]*a[i]*a[i]).

so, from the above steps the output obtained will be 1,8,27,64,125.By following the above steps we can get not only cubes but also any power of elements in a provided array.

<html> <body> <script> var a = [1,2,3,4,5]; for ( var i = 0; i < a.length;i++) { a[i] = a[i]*a[i]*a[i]; } document.write(a); </script> </body> </html>

[1, 8, 27, 64, 125]

- Related Questions & Answers
- Java program to find a cube of a given number
- How to find the cube root of a number in JavaScript?
- Java program to find the cube root of a given number
- Insert a number into a sorted array of numbers JavaScript
- Create empty array of a given size in JavaScript
- Finding closest pair sum of numbers to a given number in JavaScript
- Product of numbers present in a nested array in JavaScript
- Execute digits in even places in a JavaScript array?
- Write a program in C++ to remove duplicates from a given array of prime numbers
- Cube each element in a Numpy array
- Returning array of natural numbers between a range in JavaScript
- Transforming array of numbers to array of alphabets using JavaScript
- Java Program to cube sum of first n natural numbers
- How to execute a Javascript using Selenium in Python?
- Converting array of Numbers to cumulative sum array in JavaScript

Advertisements