Skip to content

Category: Questions

For IN Loop inside Map Javascript

Given the current example array of objects: I need to iterate through the objects and do 3 things: Delete empty objects Delete empty keys Modify key names and delete the word “dependence” The new array should look like: What I tried so far: Is there an elegant way to do this? I feel I’m muta…

Object Literal instead of switch

I would like to use object literal instead of switch statement, but i got this error: Element implicitly has an ‘any’ type because expression of type ‘string’ can’t be used to index type ‘{ apple: string[]; orange: string[]; watermelon: string[]; default: void; }’. No…

How to get textContent including childNodes?

I have some plain text content in paragraphs inside a <main> HTML element. the paragraphs are separated by new lines (n), not in <p> tags, and I would like to automatically wrap them in <p> tags using JavaScript. Example content: Inside of <main> there may be <img> elements. I wa…

How do I write a JavaScript program for the question given below

Write a function that takes three (str, c, n) arguments. Start with the end of ‘str’. Insert character c after every n characters? I think, I am using wrong method. Answer Start with the end of ‘str’. Insert character c after every n characters? I assumed this means the string needs to…

Shuffling in react

I am fetching data from an api.Trying to make quiz application from the data of an API.I have selected random countries and their respective capitals and map them to my quiz application.I have achieved this already.Now i am trying to shuffle my answer options but not able to do that.anybody can please help? H…