Skip to content

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…

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 …

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. …

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…

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 …