Java Script

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Its primary use is in rendering and allowing manipulation of web pages. Use this tag for questions regarding ECMAScript and its various dialects/implementations (excluding ActionScript and Google-Apps-Script).

62 votes
13 answers
3K views
How to get first N number of elements from an array

I am working with Javascript(ES6) /FaceBook react and trying to get the first 3 elements of an array that vari

avatar
Trudy
0 1 0 9
asked 07 September, 2021
56 votes
10 answers
2.8K views
Difference between npx and npm?

I have just started learning React, and Facebook helps in simplifying the initial setup by providing the follo

avatar
Freida
0 1 0 9
asked 07 September, 2021
59 votes
28 answers
3K views
How to set focus on an input field after rendering?

What's the react way of setting focus on a particular text field after the component is rendered? Docume

avatar
Chaya
0 1 0 9
asked 07 September, 2021
59 votes
17 answers
2.2K views
How do I conditionally add attributes to React components?

Is there a way to only add attributes to a React component if a certain condition is met? I'm supposed to

avatar
Dario
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
2.6K views
React js onClick can't pass value to method

I want to read the onClick event value properties. But when I click on it, I see something like this on the co

avatar
Daniel
0 1 0 9
asked 07 September, 2021
68 votes
11 answers
821 views
Why do we need middleware for async flow in Redux?

According to the docs, "Without middleware, Redux store only supports synchronous data flow". I don't und

avatar
Mikki
0 1 0 9
asked 07 September, 2021
51 votes
19 answers
688 views
Understanding unique keys for array children in React.js

I'm building a React component that accepts a JSON data source and creates a sortable table. Each of the

avatar
Wei
0 1 0 9
asked 07 September, 2021
61 votes
30 answers
2.1K views
React-router urls don't work when refreshing or writing manually

I'm using React-router and it works fine while I'm clicking on link buttons, but when I refresh my w

avatar
Robyn
0 1 0 9
asked 07 September, 2021
62 votes
28 answers
2.7K views
How to pass props to {this.props.children}

I'm trying to find the proper way to define some components which could be used in a generic way: <Pa

avatar
Robyn
0 1 0 9
asked 07 September, 2021
59 votes
17 answers
907 views
What does the three dots notation do in Javascript?

What does the ... do in this React (using JSX) code and what is it called? <Modal {...this.props} title=&a

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
1K views
Loop inside React JSX

I'm trying to do something like the following in React JSX (where ObjectRow is a separate component): <

avatar
Forrest
0 1 0 9
asked 07 September, 2021
56 votes
28 answers
1.4K views
How can I print a circular structure in a JSON-like format?

I have a big object I want to convert to JSON and send. However it has circular structure. I want to toss what

avatar
Forrest
0 1 0 9
asked 07 September, 2021
61 votes
22 answers
3K views
How do I convert an existing callback API to promises?

I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event:

avatar
Nereida
0 1 0 9
asked 07 September, 2021
55 votes
24 answers
1.7K views
module.exports vs exports in Node.js

I've found the following contract in a Node.js module: module.exports = exports = nano = function databas

avatar
Scot
0 1 0 9
asked 07 September, 2021
65 votes
23 answers
2.1K views
How to access POST form fields

Here is my simple form: <form id="loginformA" action="userlogin" method="post"> <div>

avatar
Kisha
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
1K views
Error: Can&apos;t set headers after they are sent to the client

I'm fairly new to Node.js and I am having some issues. I am using Node.js 4.10 and Express 2.4.3. When

avatar
Eddie
0 1 0 9
asked 07 September, 2021
61 votes
17 answers
2.7K views
Sending command line arguments to npm script

The scripts portion of my package.json currently looks like this: "scripts": { "start": "node ./script.js

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
60 votes
25 answers
1.4K views
In Node.js, how do I "include" functions from my other files?

Let's say I have a file called app.js. Pretty simple: var express = require('express'); var ap

avatar
Deedee
0 1 0 9
asked 07 September, 2021
61 votes
10 answers
1.1K views
Using Node.js require vs. ES6 import/export

In a project I'm collaborating on, we have two choices on which module system we can use: Importing modu

avatar
Chaya
0 1 0 9
asked 07 September, 2021