www.webdeveloper.com
Results 1 to 5 of 5

Thread: javascrint "in"

  1. #1
    Join Date
    Dec 2010
    Posts
    60

    javascrint "in"

    considering the code:

    Code:
    if(stuff in {red:1}){
    	alert('');	
    }
    What does the "1" mean in red:1, also can i put for loops in this argument?
    MY BLOG:
    HTML Code:
    <a href="http://teststuff.freehostingcloud.com">click here to read my game progress</a>

  2. #2
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,112
    What kind of code is that? "stuff in red?"

    Brackets usually indicate a JSON object. In the example above, "red" would be the key, and "1" would be the value.

    http://www.json.org/js.html
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  3. #3
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,112
    Here's also a quick read on "in."

    https://developer.mozilla.org/en-US/...e/Operators/in
    I'm always up for networking with fellow web professionals. Connect with me on LinkedIn if you like!

  4. #4
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    The in operator tests if a property can be found in an object. It expects left-hand side operand to be a string or a value that can be converted to a string and right-hand side to be an object. If a property exists in an object, true value is returned.

    Code:
    var test = "x", o = {x: 1};
    
    if (test in o) alert("The x is a property of o!");
    Last edited by tech_soul8; 02-07-2014 at 04:04 PM.

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,290
    Also works on associative arrays and arrays with indexes.

    Code:
    var test = 5, o = [];
    o[5]=1;
    
    if (test in o) alert("The "+test+" is a property of o!");
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles