0

I'm a new for javascript and react. I have to use "react-data-grid" library to create table sheet data then it's required Array of column and object of row.

The problem is my table have column*rows = 80*25 table my row include of data like this

let rows = [];
rows.push( { 0: "A", 1: "S", 2: "D" , 3: "F", ......., 80 : "P" );
rows.push( { 0: "Z", 1: "X", 2: "C" , 3: "V", ......., 80 : "L" );
.
.
.
rows.push( { 0: "Q", 1: "W", 2: "E" , 3: "R", ......., 80 : "M" );

I try to loop it's like code below.

const rows = [];
    for (let row = 0; row <= 25; row++){
        let objects = {};
        for (let x = 0; x < 80; x++) {
            objects[x] = {x: " "};
        }
        rows.push(objects)
    }
1
  • 6
    Instead of objects[x] = {x:' '}, try objects[x] = ' '. Commented Sep 24, 2019 at 10:51

2 Answers 2

1

Can you try something like this ?

const rows = [];
    for (let row = 0; row < 25; row++){
        let objects = {};
        for (let x = 0; x < 80; x++) {
            objects[x] = " ";
        }
        rows.push(objects)
    }

The difference is that you are creating an object instead of a key / value in your example above.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow great. only replace >>> objects[x] = {x:' '} <<< with >>>try objects[x] = ' '<<< It's work!
0

You can use

const mapObject = new Map();
mapObject.set('any key', 'any value');
mapObject.set('any key 2', 'any value 2');
mapObject.get('any key'); // any value

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.