0

here is array data

 {"start":"20160530T164500",
  "end":"20160530T173000",
 "rule":"FREQ=WEEKLY;BYDAY=MO,WE",
 "summary":"Meeting on Monday/wed"}

I have to read the rule param and based on by day, would need to create rows as below

for example, it has MO,WE so would need 2 array rows as below

{"day":"MO","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting on Monday/wed"}
{"day":"WE","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting on Monday/wed"}

experts in javascript/array...any suggestions please...

5
  • so you want loop over the structure , then for every you print the the data? Commented Mar 5, 2017 at 16:51
  • Yes..something like that...once i get BYDAY=MO,TU,WE.... it has to create array based on that BYDAY VALUES ..here it will be 3 rows... {"day":"MO","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting on Monday/wed"}{"day":"TU","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,TU,WE,","summary":"Meeting on Monday/wed"} {"day":"WE","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting on Monday/wed"} Commented Mar 5, 2017 at 16:56
  • put that code in style, its hard to read were not machines. Commented Mar 5, 2017 at 17:03
  • ya i do see that...but comment section doesnt allow me to format. see if this helps you to understand Commented Mar 5, 2017 at 17:19
  • var array1={"start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting"} into (based on byday param values var array1={"day":"MO","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting"} {"day":"WE","start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting"} Commented Mar 5, 2017 at 17:19

1 Answer 1

1
let data = {"start":"20160530T164500","end":"20160530T173000","rule":"FREQ=WEEKLY;BYDAY=MO,WE","summary":"Meeting on Monday/wed"};

let result = data['rule'];

let ans = result.split("=");

that should contain the WEEKLY;BYDAY=MO,WE WEEKLY; and BYDAY=MO,WE

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

2 Comments

use var instead , sorry i am using es6 syntax
Thanks for that..I did applied var in js..but not sure where my array loop is missing... can you please check and assist? var temprule="MO,WE"; var rulest =[]; rulest=temprule.split(','); console.log("TTTTT rulest", rulest); for(var j = 0; j < rulest.length; j++) { var day=rulest[j]; entry.day=day; console.log(entry.day) // log shows MO and WE as per loop jsondata.push(entry); // but jsondata has 2 entreies with day WE } incorrect o/p ->[{day=WE},day=WE}] expected--> [{day=MO},day=WE}]

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.