-3

Can someone please show me how to remove this error from appearing in jslint?

How do I disable it?

Videos appear: https://jsfiddle.net/xrs21efw/

https://www.jslint.com/

function onYouTubeIframeAPIReady() {

    const totalP = document.querySelectorAll("[data-container=\"play1\"]");

    for (let i = 0; i < totalP.length; i++) {

        players.add(".playSingle" + i, (playerVarsList[i] || {}));
    }
    players.add(".playInitial", {});
}

enter image description here

enter image description here

Eve Ninnall
  • 1
  • 3
  • 20
  • 3
    No, because how do I do that using my example code? – Eve Ninnall Dec 27 '22 at 06:37
  • 2
    This does not work: /*jslint for:true */ – Eve Ninnall Dec 27 '22 at 06:38
  • 1
    The correct solution is to use `forEach` method of the NodeList instead of `for` loop. – Teemu Dec 27 '22 at 06:44
  • @Teemu How do I do that? https://jsfiddle.net/xrs21efw/ Can you provide an answer? – Eve Ninnall Dec 27 '22 at 06:45
  • 1
    Umm .... what is the problem? You've used [forEach](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) of NodeList in your code already. – Teemu Dec 27 '22 at 06:47
  • 1
    Why is it using `totalP.length` as the loop length, but then using `playerVarsList[i]` inside the loop? – Barmar Dec 27 '22 at 06:47
  • 2
    @Teemu In the answer provided: jslint is saying: 'Unused '_' - How would that be fixed? – Eve Ninnall Dec 27 '22 at 07:31
  • Can the answer provided be changed or modified? – Eve Ninnall Dec 27 '22 at 07:40
  • Practically the only way is to set the warning off. I wouldn't do that, though, as the warning is useful. Maybe you should just tolerate the warning at that specific point? To really fix the issue, you've to change the data structure, currently it looks a bit messy and error prone (see Barmar's [comment](https://stackoverflow.com/questions/74926302/jslint-is-saying-unused-how-would-that-be-fixed?noredirect=1#comment132224175_74926302) above). – Teemu Dec 27 '22 at 07:47
  • 2
    @Teemu "To really fix the issue, you've to change the data structure." How would I do that in the code? – Eve Ninnall Dec 27 '22 at 07:50
  • 1
    Please don't update your question based on the comments, such edits are invalidating the existing answer(s). Rather ask a new question, when your problem changes. I can't say about the data structure, that depends on how you're going to use it in other parts of your code. In general, using numbers as the keys of an object is rarely a good choise, it can easily lead to data loss, sparse data and unwanted order when iterating the object, additionally automatically updated `length` property is not provided. Consider to use an array instead, or use more meaningful keys than numbers are. – Teemu Dec 27 '22 at 08:04
  • Like said above, I can't say without knowing more details. `playerVarsList` is currently very inconsistent, it has sparse "indexing", and the content of the indexed objects and `playerVars` are varying wildly. Anyway, if you can handle all that, maybe you could use a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) keyed with the button elements, that would connect the button and data nicely without complex looping. – Teemu Dec 27 '22 at 08:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/250673/discussion-between-mark-james-and-teemu). – Eve Ninnall Dec 27 '22 at 08:22
  • @Teemu The numbers aren't meant to be in order. The numbers are meant to be in any order that is given to it. That is how the code works. – Eve Ninnall Dec 27 '22 at 08:27
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/250674/discussion-between-mark-james-and-teemu). – Eve Ninnall Dec 27 '22 at 09:21
  • The answer provided is NOT Good Here: No videos appearing: https://jsfiddle.net/e9n4bk8z/ Videos appear here: https://jsfiddle.net/xrs21efw/ – Eve Ninnall Dec 27 '22 at 09:22
  • 1
    If an answer doesn't solve the problem, then please address the problems with it in comments on the answer. Rewriting your entire question to be a complaint about that answer just makes it hard for people to write a new answer about the actual problem. – Quentin Dec 27 '22 at 09:23
  • Note that JSLint isn't really used much these days. [ESLint](https://eslint.org/) has been adopted by the industry as the linter practically everybody uses. – Quentin Dec 27 '22 at 09:26

1 Answers1

0

try the following:

totalP.forEach((_, index) => {
            players.add(".playSingle" + index, (playerVarsList[index] || {}));
    })
White Wizard
  • 608
  • 3
  • 19
  • 3
    The answer provided is *NOT* *Good* Here: No videos appearing: https://jsfiddle.net/e9n4bk8z/ Videos appear here: https://jsfiddle.net/xrs21efw/ – Eve Ninnall Dec 27 '22 at 09:11
  • 2
    @MarkJames — The problem with the first link is due to the **other** change you made; not the one White Wizard recommended. – Quentin Dec 27 '22 at 09:31