Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getObjectFormat(title,childRows,key){
- var setKey = (key == null)?("childRows"):(key);
- return {
- title: title,
- [setKey]: childRows
- };
- };
- function createChildRows(array,childRows,key = null){
- var array = array.reverse();
- array = array.filter(function(n){return (n != undefined && n != "") });
- // Initial child rows
- var formate = getObjectFormat(array[0],childRows,key);
- for(var i = 1; i < (array.length); i++){
- formate = getObjectFormat(array[i],formate,key);
- };
- return formate;
- };
- // Demo call. Console the result of generated dynamic Json Objects
- var array = ("test1|test2|test3|test4").split("|");
- console.log(createChildRows(array,{"title":"Last Child Row"},"more"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement