Skip to content

Tag: arrays

Checking for duplicate strings in JavaScript array

I have JS array with strings, for example: I need to compare for duplicate strings inside array, and if duplicate string exists, there should be alert box pointing to that string. I was trying to compare it with for loop, but I don’t know how to write code so that array checks its own strings for duplic…

JSON to XML Using Javascript

I am trying to convert the JSON to XML but not getting exact output.In My JSON having array object it not converting that to XML array.Mainly array object is not converting into XML as expected Actual Output: Expected Output: Please guide me if i am missing anything from the code to get my expected result Ans…

How to flatten nested array of object using es6

I have this array of objects, within it I have another array of objects: How to get flat array of country like this: without using a forEach and a temp variable? When I did: I got the same structure back. Answer Latest edit All modern JS environments now support Array.prototype.flat and Array.prototype.flatMa…

How to check if key exists in array of object

I am trying to find out if the given key exists in array of object. if the value key exists then i want to return true else false. i giving input of key from text box and then checking if the key exists in array of objects, but i couldn’t get it. here is what i have tried code: if

Create a nested array recursively in Node.js

Following is my array and I want to have objects nested like this as output : Please help me with a recursive function to do this in node.js. Following is the recursive function is what I have tried: Please help me to solve this. I am a newbie in this. Answer Renaming some variables helped me solve this. getN…

How to use Array.from with a XPathResult?

When I use querySelectorAll, I can find 138 td nodes in my sample document. When I do the same with XPath, I get no result: Although there is at least one match: The problem seems to be that Array.from can not iterate over a XPathResult. Even this returns 0: How to make a XPathResult suitable for Array.from? …

Javascript: adjacent Elements Product algorithm

I’m trying to solve a basic javascript algorithm and i’m kinda stuck, here is the question: Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. Example For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProdu…