Category "ecmascript-6"

How to modify & replace the key an object by comparing it with other objects?

I have an array of object which consists some id's as a key. const sampleObj1 = {0011:[{},{}], 0022:[{}, {}], 0033:[{},{}]} const sampleObj2 = [{id:0011, name:'

Javascript Custom Array.prototype.method logs 'not defined' [duplicate]

So, I've never done this before, trying to add a method to the Array.prototype. See console.log statement below for usage. It keeps telling

question regarding max value in an array with recursion in JavaScript

Currently, I was able to get the following function to retreive the max value from an array through recursion const max = ([a,...rest]) => !rest.length || a

Code works (mostly). But failure to remove duplicates

Summary: Hey I've got a filter for some data. It's filtering fine but it's not removing duplicate objects. Arguments taken in order: 1. datasource 2. filters (r

Why does partial application work when currying but not with .bind()?

I'm practicing partial application of a function, that is, fixing function arguments. I've learned two ways to achieve it: By currying the original function fir

is it possible to write an es6 onChange arrow function?

What's the correct syntax for the onChange es6 function? function myEvent(e){ console.log(e.target) } <select onChange=(event)=>{console.log(event.ta

Create an array of object properties for each item that has the same key

I'm merging two objects together to create a filter object. However I want to group the merged objects property values where the keys are the same. So... [{cate

Destructuring Nested objects in javascript | Destructure second level parent and child Objects

I need to destructure and get values of title, child, childTitle from this object const obj1 = { title : 'foo', child : { title2 : 'bar' } } le

What is the lifetime of the variables declared inside component file in React?

Consider the React code declared inside LoremComponent.tsx below: const foo = "bar"; export default (props) => { return ( <h1>{foo}</h1>

How to check whether all number elements in an array are even numbers with recursion?

I'm currently learning as much as I can about recursion but I'm really stuck on how to use it to check whether all the number elements in an array are even numb

How do I build a Regexp that doesn't care about positions

I'm making a Scrabble game with HTML and Javascript and I'd like to add a "hint word" feature based on the player's rack. I have a dictionary array with the val

What's the difference between using "let" and "var"?

ECMAScript 6 introduced the let statement. I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the

(JavaScript) Best was to check for multiple conditions and end execution as soon as one returns false?

I am currently working on a duty rota App. I need to calculate which employee can work on every particular day of the month. This must also be updated "on the f

Produce CSV from JSON object

I have a JSON Object like so that I am trying to produce a CSV from { "football": { "count": 2109, "emailed": 0, "optin": 2109,

How to import a JSON5 file (as one can regular JSON) in Typescript?

I would like to import a JSON5 file into a Javascript object in the same way [one can import a JSON file](import config from '../config.json'). Shows this mess

How to pass document variable to ES6 Module during Jasmine testing

I want to test if a function in a module generated something in document but I am having trouble defining the document variable. I have simulated it jsdom but I

IntersectionObserver does not work on small screens for long sections JS

This script issues the active class for the active section. Recently noticed that it stops working on small screens. Even in the developer's console in chrome,

Generate array with values A1, A2, A3, B1, B2, B3... etc?

I'm trying to generate an array of objects where it outputs an array looking like this: [ { _id: 2, label: 'A1' }, { _id: 3,

What was the motivation for introducing a separate microtask queue which the event loop prioritises over the task queue?

My understanding of how asynchronous tasks are scheduled in JS Please do correct me if I'm wrong about anything: The JS runtime engine agents are driven by an e

Change Button Text in loop using React

Is it possible to change button text that is created using array. If it is possible, what should I do with the onClick function in the button. Here is the sampl