Answers for "how to split a number into an array javascript"

9

javascript split array into chuncks of

function splitArrayIntoChunksOfLen(arr, len) {
  var chunks = [], i = 0, n = arr.length;
  while (i < n) {
    chunks.push(arr.slice(i, i += len));
  }
  return chunks;
}
var alphabet=['a','b','c','d','e','f'];
var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2); //split into chunks of two
Posted by: Guest on August-02-2019
3

turn number into array javascript

const myNumber = 1245;
function numberToArray(number) {
  	let array = number.toString().split("");//stringify the number, then make each digit an item in an array
  	return array.map(x => parseInt(x));//convert all the items back into numbers
}
//use the function
var myArray = numberToArray(myNumber);
Posted by: Guest on April-02-2020
0

javascript split numbers into array

var n =  123456789;
var digits = (""+n).split("");
Posted by: Guest on August-14-2021
1

HOW TO SPLIT AN ARRAY JAVASCRIPT

array.splice(index, number, item1, ....., itemN)
Posted by: Guest on November-17-2019

Code answers related to "how to split a number into an array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language