Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8666525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:45:18+00:00 2026-06-12T17:45:18+00:00

Some usage that I find a bit tricky is 2 in [1, 3, 5]

  • 0

Some usage that I find a bit tricky is

2 in [1, 3, 5]

for (var i in [1, 3, 5]) { ... }

str = "hello";
for (var i in str) { ... }

the first one is true (I might have immediately said 2 in [1, 3, 5] is false), and the second line loops through 0, 1, 2 instead of 1, 3, 5, and the last part loops through 0 to 4, instead of 'h', 'e', 'l', 'l', 'o'. Right now I am just using: whenever seeing in for array, or for-in loop for array, immediately think about index instead. Otherwise, is there a way or usage pattern that we can use to avoid this pitfall?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:45:19+00:00Added an answer on June 12, 2026 at 5:45 pm

    Yes, it’s called “do not use in for arrays”. It tests if an object has a certain key – so you cannot properly use it on arrays.

    You also shouldn’t use for(var x in something) unless you want to iterate over the properties of something.

    To check if a value is contained in an array use ~arr.indexOf(value) – or arr.IndexOf(value) != -1 if you want it more verbose.

    To iterate over the elements in an array use for(var i = 0; i < arr.length; i++)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PL/SQL code that I think might have a memory leak. Everytime
I have some dirty resource usage records in t_resourcetable which looks like this resNo
Please give me some examples of jump table usage. I have seen this example
I am trying to find some good resources that will help me understand how
We're trying to get some usage metrics on a VB6 application that we are
This question might be a bit long and specific, but I have been attempting
I'm new to CMake and have trouble understanding some usage concepts. I'm calling a
I have the following XML example that I need some help on. The sample
I have a command-line utility that gets quite a bit of downloads from my
For some reason, I've always assumed that readonly fields have overhead associated with them,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.