Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Square Every Digit javascript

function squareDigits(num){
  let string = num.toString();  // turn number to a string
  let results = [];             // create an array to save the new values of the string
  for (let i = 0; i < string.length; i++){  // iterate through the string
      results[i] = string[i] * string[i];   // save the square of the number to the array 
  }
  return Number(results.join(''));    // turn the array into a string and then into a number
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get first 3 characters of string 
Javascript :: javascript get date midnight today 
Javascript :: javascript convert string to float with 2 decimal places 
Javascript :: url regex 
Javascript :: javascript iterate over object 
Javascript :: js add click listener 
Javascript :: round up javascript 
Javascript :: Required a safe HTML, got a ResourceURL 
Javascript :: how to append more elements after click in react 
Javascript :: convert string array to objectid mongoose 
Javascript :: react native gradient touchable feedback 
Javascript :: jquery create element 
Javascript :: add an element to the front of an input list in javascript 
Javascript :: discord.js reliablehandler 
Javascript :: stun server 
Javascript :: add last element in array javascript 
Javascript :: first remove active class from classlist and append to current element using javascript 
Javascript :: express js params 
Javascript :: jest test coverage command 
Javascript :: send form data with file upload using ajax 
Javascript :: 16/27.5 
Javascript :: remove undefined from array javascript 
Javascript :: javascript get index of object in array 
Javascript :: how to check if user is typing discord js 
Javascript :: use set to remove duplicates in javascript 
Javascript :: efault loader is not compatible with `next export`. 
Javascript :: javascript ceiling 
Javascript :: set focus javascript 
Javascript :: JavaScript the last word of a string 
Javascript :: bootstrap tabs click event jquery 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =