javascript - unused argument 'idtype' although called from a .map() function

Miha Šušteršič

I am trying to re-write a function that filters out a specific property of an object to a function that can be passed a property and filter it.

This is the initial function:

function filterCategory(xmlObject, id) {
  let newData = [];
  xmlObject
      .Sports[0]
      .Sport[0]
      .Category
      .map(function (category) {
        if (category.$.CategoryID == id) {
          newData.push(category);
        }
      });
  xmlObject
      .Sports[0]
      .Sport[0]
      .Category = newData;
  return xmlObject;
}

This is my new function:

function filterProperty(xmlObject, property, idtype, id) {
  let newData = [];

  if(xmlObject.hasOwnProperty(property)) {
    xmlObject.property.map(function(value) {
      if(value.$.idtype == id) {
        newData.push(value);
      }
    });
    xmlObject.property = newData;
  }
  return xmlObject;
}

For the second function my linter returns Unused idtype. Will my function be able to access the argument, or will it fail because I am trying to call it from a map() function? If so, how can I avoid this?

Dymos

If you want to use idtype as a dynamic object property, then you can't use it like my.object.idtype as that will look for the property on the object that is literally called "idtype", instead you can use bracket notation to access the property

value.$[idtype];

Further illustration:

var obj = { one: 1, two: 2, three: 'foobarbaz' };

function getThingFromObject(mything) {  
  return obj[mything];
}

console.log(getThingFromObject('one')); // 1
console.log(getThingFromObject('three')); // 'foobarbaz'

  

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Javascript

Standard conventions for indicating a function argument is unused in JavaScript

From Dev

Cannot pass array object from map function as argument javascript

From Dev

"{...} is not a function" although never called as a function

From Dev

Javascript testing - function called with specfic argument

From Dev

javascript function is not being called if i pass a argument

From Dev

How do I write a Java method, to be called from server side JavaScript, that takes a JS callback function as an argument?

From Dev

Javascript function not called from php

From Dev

Called function as an argument type

From Dev

Destructor of function argument called

From Dev

Object turns into undefined when passed to function as argument and method is called JavaScript

From Dev

How to pass a dict as argument in a called matlab function from Python

From Dev

Passing an if condition as function argument - Error unused arguments

From Dev

Declare a type with unused type function argument

From Dev

What is the difference between a Rust function with no argument and a function with one unused argument?

From Dev

Javascript function is not being called from code behind

From Dev

passing array as javascript function argument from php

From Dev

calling javascript function with an argument from html

From Dev

Error from terra: unused argument (type = "xyz")

From Dev

Function not called in map

From Dev

Unused argument

From Dev

passing argument to map function

From Dev

second argument in map function

From Dev

function argument as map value

From Dev

How to map a 0-argument JavaScript function in PureScript FFI

From Dev

Type inference of function resolved from a map and called indirectly

From Dev

How to pass keyword argument to function called by concurrent.futures map call

From Dev

Function as an argument to a function in Javascript

From Dev

`javascript` Can we use map function again using map function argument value?

From Dev

Function prints infinitely when in loop, although it's not called repeatedly

Related Related

  1. 1

    Standard conventions for indicating a function argument is unused in JavaScript

  2. 2

    Cannot pass array object from map function as argument javascript

  3. 3

    "{...} is not a function" although never called as a function

  4. 4

    Javascript testing - function called with specfic argument

  5. 5

    javascript function is not being called if i pass a argument

  6. 6

    How do I write a Java method, to be called from server side JavaScript, that takes a JS callback function as an argument?

  7. 7

    Javascript function not called from php

  8. 8

    Called function as an argument type

  9. 9

    Destructor of function argument called

  10. 10

    Object turns into undefined when passed to function as argument and method is called JavaScript

  11. 11

    How to pass a dict as argument in a called matlab function from Python

  12. 12

    Passing an if condition as function argument - Error unused arguments

  13. 13

    Declare a type with unused type function argument

  14. 14

    What is the difference between a Rust function with no argument and a function with one unused argument?

  15. 15

    Javascript function is not being called from code behind

  16. 16

    passing array as javascript function argument from php

  17. 17

    calling javascript function with an argument from html

  18. 18

    Error from terra: unused argument (type = "xyz")

  19. 19

    Function not called in map

  20. 20

    Unused argument

  21. 21

    passing argument to map function

  22. 22

    second argument in map function

  23. 23

    function argument as map value

  24. 24

    How to map a 0-argument JavaScript function in PureScript FFI

  25. 25

    Type inference of function resolved from a map and called indirectly

  26. 26

    How to pass keyword argument to function called by concurrent.futures map call

  27. 27

    Function as an argument to a function in Javascript

  28. 28

    `javascript` Can we use map function again using map function argument value?

  29. 29

    Function prints infinitely when in loop, although it's not called repeatedly

HotTag

Archive