0

I am working on Shopify and creating a d3 chart. I tried to pass data from Shopify liquid to javascript. The codes are as shown in the fiddle.

var temp_test = {
  "events": []
};
var test = [
  [
    "<p>Everything is fresh. delicious and good.</p>",
    undefined,
    "12-23-2000",
    "test",
    "Start"
  ],
  [
    "<p>Everything is fresh. delicious and good.</p>",
    undefined,
    "12-23-2000",
    "test",
    "Start"
  ]
];

test.forEach(function(data) {
  temp_test.events.push({
    "title": data[0],
    "image": data[1],
    "date": data[2],
    "content_1": data[3],
    "content_2": data[4]
  });
});
console.log('check for nan', temp_test);

https://jsfiddle.net/be83yk54/22/

(Strangely, the fiddle works just fine but Shopify does not and it is not Shopify problem).

console.log shows the data just fine, but when I click on the data to expand the object, the string is converted to number automatically and I got NaN instead of formatted date.

before

after

Govind Samrow
  • 9,981
  • 13
  • 53
  • 90
Zaw Moe Lwin
  • 13
  • 1
  • 4
  • 2
    Possible duplicate of [Why does Date.parse give incorrect results?](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) – CBroe Aug 01 '18 at 06:41
  • I am not trying to parse. The data is automatically converted on expansion of the object in the console as shown in the screenshot. – Zaw Moe Lwin Aug 01 '18 at 06:45
  • Your fiddle doesn’t show the result your screenshot shows, when I test it in Firefox. – CBroe Aug 01 '18 at 06:51
  • The code in the fiddle works fine, as CBroe also pointed out. I think it's safe to assume the problem is not within the given code sample. – Berry M. Aug 01 '18 at 06:52
  • yeah. you are right. @BerryM. I was manipulating the object after the log and mistakenly thought it is Shopify data passing error. – Zaw Moe Lwin Aug 01 '18 at 07:17

1 Answers1

0

I think I got what happened. When I console.log the data the data correct. but the array object might be manipulated in d3 which caused the object data change and when expanding the object, the data is already changed.

Zaw Moe Lwin
  • 13
  • 1
  • 4