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 7762093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:18:17+00:00 2026-06-01T14:18:17+00:00

I’m a little confused with my array creation. I have a list of items

  • 0

I’m a little confused with my array creation. I have a list of items with x:y co ordinates and also their dimensions (in grid sizes) … for example:

x: 1
y: 7
width: 2 tiles
height: 2 tiles

So the idea im trying to do is create an array of x:y grids that are “occupied”. But looping such data so the occupied tiles would there for be:

x: 1
y: 7
//
x: 2
y: 7
//
x: 1
y: 8
//
x: 2
y: 8

Because in the above example the item is 2 by 2 tiles ( a square ).

My object is structured like this (shown in console.log(sdata);)

7: Array[4]
0: "1"
1: "7"
2: "2"
3: "2"

So yeah im trying to make an array to store this kind of grid reference..Hope I explained what I trying to get at, but i can’t work out how to structure a loop to create the array.

  • 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-01T14:18:18+00:00Added an answer on June 1, 2026 at 2:18 pm

    http://jsfiddle.net/rlemon/JeeV2/ Here is an example of how you could produce this type of ‘grid’ occupied data..

    var chords = [ // instead of arrays we'll use objects.. they're nicer. 
        {
        x: 1,
        y: 7,
        h: 2, // height
        w: 2}, // width
    { // ohh look a second plot point.
        x: 4,
        y: 1,
        h: 3,
        w: 2},
    ];
    
    var occupied = { // will be your cells points occupied
        x: [],
        y: []    
    };
    chords.forEach(function(chord) { // now lets loop the chords and produce the occupied array
        occupied.x.push( chord.x );
        occupied.x.push( chord.x + (chord.w-1) ); // expand the width of the cell - initial point
        occupied.y.push( chord.y );
        occupied.y.push( chord.y + (chord.h-1) ); // expand the height of the cell - initial point
    });
    console.log( occupied );
    // outputs
    ​Object
        x: Array[4]
            0: 1
            1: 2
            2: 4
            3: 5
    
        y: Array[4]
            0: 7
            1: 8
            2: 1
            3: 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have an array which has BIG numbers and small numbers in it. I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.