Jump to content

Get correct row from an array?


EchoFool

Recommended Posts

Hey

 

 

I have an array which carries id's + 4 numbers assigned to each id.

 

 

I'm trying to find a way to use if statement to get the correct id by checking which of the 4 numbers goes with the check.

 

 

This is the structure:

 

 


				var listObj = {
									id: uid,
									data: [
										abposx,
										abposy,
										width,
										height
									]
								};	

 

 

So lets say im trying to find the "id" which greater than the width & height and its abposx and abposy and greater than what im checking...

 

 

The issue is how do i get the id from such a check =/ its confusing?

Link to comment
Share on other sites

Is looping the entire array the only way? As it sounds quite intensive.

 

Also how can you loop an array in such a way to check if the values are between the values like:

 

Logic code:

get id where x is > data[0] && y > data[1] && x < data[2] && y < data[3]

Link to comment
Share on other sites

How else are you going to find what you want unless you're prepared to search the entire array? The only way was if the array was sorted or otherwise preprocessed, but to do that from scratch you'd still have to look at everything.

 

Your logic is great but plain JavaScript doesn't work like that. As you still haven't said whether you want just one id or all the matching ids, for one the logic is

looking at each item in the array, if x > data[0] and y > data[1] and x 

and for many
[code]start with an empty list. looking at each item in the array, if x > data[0] and such then add the id to the list. after searching the array, return the list
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.