---
title: "How to insert an List of string array into a table rows in Javascript"  
description: "How to insert an List of string array into a table rows in Javascript"  
author: "Anonymous User"  
published: 2013-12-17  
updated: 2013-12-17  
canonical: https://www.mindstick.com/forum/1786/how-to-insert-an-list-of-string-array-into-a-table-rows-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 2 minutes  

---

# How to insert an List of string array into a table rows in Javascript

Hi I have a [MVC project](https://www.mindstick.com/forum/158706/how-do-you-establish-a-database-connection-in-an-asp-dot-net-mvc-project) and I am calling a POST to get data from [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)-side which works great!

I have a [bootstrap](https://www.mindstick.com/articles/1555/image-viewer-using-bootstrap-carousel) css table to which I want to bind all the data in the call back [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) for POST.

## Below is my code snippet:

## JS:

```
dataButton.on("click", function GetTRS() {        var objectID = updateFeature.attributes.OBJECTID;        var Direction = updateFeature.attributes.DIR;        var Township = updateFeature.attributes.TWNSHP;        var Range = updateFeature.attributes.RNG;        var Section = updateFeature.attributes.SECTION_;        $.post("/Home/Index", { "T": Township, "R": Range, "S": Section }, function (data) {}, 'json');    });
```

## HTML

```
div class="container"><table class="Computed CIR table table-bordered">    <thead>        <tr>            <th style="text-align: center"><b>Crop</b></th>            <th style="text-align: center"><b>ET (inches)</b></th>            <th style="text-align: center"><b>Eff.Rain (inches)</b></th>            <th style="text-align: center"><b>CIR (inches)</b></th>            <th style="text-align: center"><b>Recharge (inches)</b></th>        </tr>    </thead>    <tbody data-bind="foreach: data">        <tr>            <td style="text-align: center" data-bind="text: opCropName"></td>            <td style="text-align: center" data-bind="text: opET"></td>            <td style="text-align: center" data-bind="text: opEffRain"></td>            <td style="text-align: center" data-bind="text: opCIR"></td>            <td style="text-align: center" data-bind="text: opRecharge"></td>        </tr>    </tbody></table>
```

The data returned from post is a LIST of [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) [arrays](https://www.mindstick.com/articles/11955/arrays-and-its-limitations) with each array having the five data types I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to bind to the cells in each row of the table.

[Thank you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance)!!

## Replies

### Reply by Pravesh Singh

Hi jayPrakash,

\
The data that comes back in your callback needs to be attached to your viewmodel somehow. I'm not sure how you're creating your viewmodel, but if you have something like this:

```
var vm = {    data: ko.observableArray([])}
```

\

then you'd need to update that data array in your ajax callback.

$.post("/Home/Index",

{ "T": Township, "R": Range, "S": Section },

function (data) { vm.data(data); }, 'json');

\

That assumes that your data observable array is holding plain old JavaScript objects, which is fine. If however, you need these objects to be mapped over to objects with knockout observables, then you'd have to map it somehow. You could either map everything over manually, or use knockout's mapper.


---

Original Source: https://www.mindstick.com/forum/1786/how-to-insert-an-list-of-string-array-into-a-table-rows-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
