variable name as a string in Javascript function
const myFirstName = 'John'
Object.keys({myFirstName})[0]
// returns "myFirstName"var a = [1, 3, 4, 3]
var b = [1, 5, 6, 7]
var c = [3, 4, 8, 9]
function arraySum(x, varName) {
var sum = 0
for (let i = 0; i < x.length; i++) {
sum += x[i]
}
console.log("sum of " + varName + " is " + sum)
}
arraySum(a, "a");
Also in JavaScript:
- javascript console
- javascript element read attribute
- button not exist js
- device height react native
- array destructuring
- react catch error in component
- js string to node
- disable input jquery
- insanceof
- dart how to convert json to x-www-form-urlencoded
- how to change string to array in javascript
- use redux in gatsby
- how to get selected list item value in javascript
- admob react native
- react tomcat
- javascript add commas to number
- arrondi js
- how to reset settimeout in javascript
- electron file association
- cm to inches
- how to get the last element of an array in javascript
- query selector js
- Javascript convert html entity to string
- electron Uncaught ReferenceError: require is not defined at recorder.js:1