Skip to content
Advertisement

Tag: arrays

Sorting with Number and Strings in array of objects

I have array like this : How to sort this array so that, when ascending unlimited comes at the last index and when descending unlimited comes at the top index. Answer The simplest may be to use the “standard” numerical sort for ascending, and when you need descending, then just apply .reverse() to it as an extra action:

build array of object from tree object

I’m trying to get into javascript’s built-in reduce function and with the help of that build objects inside array. But you can use whatever function or method you want. Expected output What I tried to do I created a function which takes array as an argument and calls reduce for each array’s element. But it gives me output that I

Append to array in async for loop

I’ve got this function which contains other nested async functions. I’m unzipping a zipfile and then appending each HTMLImageElement to an array. However, the array is printing like this 16 is the correct number of images I’m expecting, but they’re undefined when I console.log() them. I’m mapping the promise of each image to an array then doing Promise.all() on this

Converting nested loops into forEach();

Im trying to learn forEach() method but i cant find more advanced examples. So i thought about refactoring my Codewars code to learn from it. I dont know know to properly use forEach method in nested loops. Hope You can help me learn from this example 🙂 6 kyu – Replace With Alphabet Position https://www.codewars.com/kata/546f922b54af40e1e90001da/train/javascript Answer (Note: @Terry’s solution is

Javascritpt – Looping through an array

So i just started learning js and i can’t solve this excercise: Create a file named looping-through-arrays.js. In that file, define a variable named pets that references this array: [‘cat’, ‘dog’, ‘rat’] Create a for loop that changes each string in the array so that they are plural. You will use a statement like this inside the for loop: pets[i]

Advertisement