0

I have the following line in javascript

$.each(words, function (key, val) {

However, in jslint and jshint I keep on getting the below

unused variable key

I want to know how to fix this through coding.I read this post JSLint message: Unused variables . HOwever, I want to know if it is possible if I can fix this through coding rather than writing a comment to ignore it?

Community
  • 1
  • 1
Hello Universe
  • 3,248
  • 7
  • 50
  • 86
  • 1
    Comments are the way to go. I don't see the reason for trying to fix something that's not broken. – Miguel Mota Aug 23 '14 at 09:57
  • 1
    Maybe duplicate of [JSLint message: Unused variables](http://stackoverflow.com/questions/6583623/jslint-message-unused-variables) – Volune Aug 23 '14 at 09:59

2 Answers2

1

You can use for loop if words is purely an array.

for(var i=0; i<words.length; i++){
Viswanath Donthi
  • 1,791
  • 1
  • 11
  • 12
1

You could "fix" it by doing something with the variable, but you don't need to. It is a warning (not an error), and one that is expected in an each loop.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335