Giter VIP home page Giter VIP logo

Comments (2)

mestaritonttu avatar mestaritonttu commented on June 15, 2024

@camsong this is not fixed yet, please reopen.

from you-dont-need-jquery.

vlakoff avatar vlakoff commented on June 15, 2024

Refs the relevant section: https://github.com/camsong/You-Dont-Need-jQuery#6.1

A confusion seems to have been introduced at some point, because $.inArray() doesn't return a boolean (item found or not), but the index of the item, exactly as Array.prototype.indexOf() does. (Indeed, that jQuery function has been badly named.)

Therefore, the correct snippets are:

  • Search for a specified value within an array and return its index (or -1 if not found):
// jQuery
$.inArray(item, array);

// Native, and ES6-way
array.indexOf(item);
  • Test if a specified value is found within an array:
// jQuery
$.inArray(item, array) > -1;

// Native
array.indexOf(item) > -1;

// ES6-way
array.includes(item);

from you-dont-need-jquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.