0

I want to convert the data of a html table into json set its key.

var tbl = $('#table-availed-prod tr').map(function () { return $(this).find('td').map(function () { return $(this).html(); }).get(); }).get(); 

What I get is this

JSON :

IMAGE

OR

Array(){ 0: "Sophos" 1: "Complementary" 2: "Codey Ropen" } 

What I need is something like this

JSON :

[{ Productname:"Sophos", ProductTypename:"Software", AssignedPerson:"Codey" }, { Productname:"Sophos", ProductTypename:"Software", AssignedPerson:"Codey" }, { Productname:"Sophos", ProductTypename:"Software", AssignedPerson:"Codey" }] 

My Table: Table Image

1
  • 1
    Similar question is answered here Commented Mar 20, 2019 at 4:57

1 Answer 1

3

Try this approach.

var arr1 = []; var carr = ['product name', 'product type', 'assigned person']; $("#table-availed-prod tr").map(function(i, tr){	var arr = {};	$(this).find('td').map(function(j, td){ if(carr.indexOf(j) !== -1){	arr[carr[j]] = $(this).text();	}	});	arr1.push(arr); }); console.log(arr1);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.