JavaScript Javascript some() method and additional parameter javascript some method,javascript array some method,javascript object some

If you want to pass an additional parameter to the function that is placed inside the some method you can use bind.

var myArray = ['a', 'b', 'c', 'd'];
var otherValue = 'e';
function someFunction(externalParameter, element, index, array) {
    console.log(externalParameter, element, index, array);
    return (element == externalParameter);
}
myArray.some(someFunction.bind(null, otherValue));

This would give you:

e a 0 ["a", "b", "c", "d"]
e b 1 ["a", "b", "c", "d"]
e c 2 ["a", "b", "c", "d"]
e d 3 ["a", "b", "c", "d"]
false
Answer:1

Using a closure looks like the simplest solution :

var additonalValue = 79;
var r = myArray.some(function(previousValue) {
    return additonalValue.indexOf(previousValue) + previousValue.indexOf(additonalValue) < -1;
});
Answer:2

I trying to add click() event for dynamically created button like this HTML <div></div> <button>generate new element</button> Jquery $("button").click(function() { $("...

I trying to add click() event for dynamically created button like this HTML <div></div> <button>generate new element</button> Jquery $("button").click(function() { $("...

  1. click event dynamically created button jquery
  2. jquery click dynamically created element
  3. click on dynamically created button
  4. click function on dynamically created element
  5. click event on dynamically created element jquery
  6. jquery bind click dynamically created element
  7. click event for dynamically created button javascript
  8. click function for dynamically created button jquery
  9. click function on dynamically created element jquery
  10. click event for dynamically created button in asp.net c#
  11. click event for dynamically created li in jquery
  12. click event for dynamically created button c#
  13. trigger click on dynamically created element

The Problem: The call back on my $.getJSON request doesn't run. On page load, nothing is logged to the console or updated on the page, but when the function is pasted in to the console it executes ...

The Problem: The call back on my $.getJSON request doesn't run. On page load, nothing is logged to the console or updated on the page, but when the function is pasted in to the console it executes ...

I need to pass a dynamic param to an applet. This is my controller: 'use strict'; angular.module('jworkApp') .controller('AppletCtrl',['$scope', function (scope) { scope....

I need to pass a dynamic param to an applet. This is my controller: 'use strict'; angular.module('jworkApp') .controller('AppletCtrl',['$scope', function (scope) { scope....

Using Fabric.js, I'm having trouble truly rotating a triangle around its center point, or at least what I believe should be the center point. I created a jsFiddle that demonstrates. The triangle is ...

Using Fabric.js, I'm having trouble truly rotating a triangle around its center point, or at least what I believe should be the center point. I created a jsFiddle that demonstrates. The triangle is ...