All Questions
3,231 questions
0
votes
0
answers
18
views
How do I return Error with non-integer parameters? [duplicate]
const sumAll = function(x, y) {
let sum = 0;
if (x < 0 || y< 0 || isNaN(x) || isNaN(y) || Number(x) !== x || Number(y) !== y ) {
return "ERROR";
} else { if (x > y) {
...
0
votes
2
answers
72
views
Loop through a state array in React and switch each item to true using setTimeout
I have an array in state:
const [show, setShow] = useState([false, false, false, false])
These affect whether or not an image is displayed.
I'd like to iterate through them one by one, using a delay ...
1
vote
2
answers
67
views
how to change array of object based on condition using javascript
I would like to know how to shift based on field that contains numeric string and normal string.
so, if numeric string value then shift to end of array, rest remain same
Tried
const sortData = arrobj....
4
votes
1
answer
88
views
How to transform flat array to a list of hierarchical trees based on a field with a list of enums denoting the level
I'm trying to transform a flat list of account balances to a list of hierarchical account trees based on a list of unique codes. I'm struggling with how to solve this as I can't see what steps to take....
-3
votes
1
answer
71
views
Iterate nested array of objects and get result as array of object [closed]
I am stuck at a problem and i would really need some guidance on the solution.
I have an object like this shown below
{
"count": 3,
"tree": [
{
"name": &...
0
votes
1
answer
66
views
Find index in map object using JavaScript
If we want to find index in array of objects, it's pretty simple. Example below
let a = [
{prop1:"abc",prop2:"qwe"},
{prop1:"bnmb",prop2:"yutu"},
{prop1:&...
0
votes
1
answer
56
views
filter map objects using javascript
I have a map object with key value pair as shown below
const input = new Map([
[
0,
{
testErrorSummary: "ServiceC\nV4/\n\tcom.dmv.smp",
appErrorSummary: '{&...
1
vote
1
answer
51
views
Using a looped element as a new child in replaceChild() method
const addToCartButtons = document.getElementsByClassName('add-to-cart');
const addToCartButtonsArray = Array.from(addToCartButtons);
const increment = document.createElement('img');
increment....
0
votes
1
answer
44
views
Is there a way to use replaceChildren() on looped elements when hovering over them?
const addToCartButtons = document.getElementsByClassName('add-to-cart');
const products = document.getElementsByClassName('product');
const addToCartButtonsArray = Array.from(addToCartButtons);
...
-2
votes
1
answer
59
views
getJSON loop in Jquery dosent return all objects
I have a specific problem.
I have one JSON file that contains all JSON files in a folder.
I am iterating through that in a function where i create an array,
I take that array and send it to another ...
0
votes
2
answers
57
views
How to iterate the sequence of for(let i=0;i<n;i++){arr.splice(arr.length/2,0,i);} (eg:n=6 : 1,3,5,4,2,0), but not create arr first?
For example, I have some sequence that comes from pushing indexes to an array into middle contineously:
const n=6;
const arr=[];
for(let i=0;i<n;i++){
arr.splice(arr.length/2,0,i);
}
document....
1
vote
1
answer
46
views
Assigning character specific values to many variables utilizing a loop JavaScript
I am trying to figure out a way to assign tile values to my tictactoe cell variables equivalent to the variable characters themselves in a more concise manner. Each variable should be equivalent to ...
-1
votes
2
answers
49
views
Extracting values from array and adding them to new elements
I've got some code which loops through an array of products, it records new categories found and also how many times a category is found:
const categoriesFound = (catArray) => {
let categories = {...
3
votes
1
answer
80
views
javascript setting a .map() range and update the range later
I'm building an app with React & JS which returns products from a json list inside a component, the array is outputted on the app using a .map() array. I'm also limiting the amount to return ...
-4
votes
1
answer
72
views
Javascript Object Array, Iterate over only one object
I have a javascript array object. I want to find the result of a single array. The following code does what I want but always iterates over the whole array. How can I achieve the same on just one ...