• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Create Object runtime in javaScript

Guys, Could you help me with my javascript. I just want to create a Object at runtime.

I was debuging the code and show me 6 parameters and i passed just 2 ..

Does anyone could help me with that please ?
-----------------------------------------------------

        function CreateObj(args) {
            var newobj = {};
            alert(args.length);
            for (var v = 0; v < args.length; v++) {
                var t =  ".param" + v.toString();
                newobj[t] = args[v];
            }
            return newobj;
        }

        $(document).ready(function () {
            var obj = CreateObj("michel", "mortarello");
        });
0
Mortarello
Asked:
Mortarello
  • 2
1 Solution
 
Gurvinder Pal SinghCommented:
try replacing this line
   var t =  ".param" + v.toString();
   newobj[t] = args[v];

by this

newobj[ "param" + v ] = args[ v ];

0
 
MortarelloAuthor Commented:
Hi gurvinder372,

I Think i found the problem. When i passed ("michel","mortarello")..the javascript is itereting only in "michel"
That's why is showing 6 parameters ..I will try to pass a array now..

0
 
MortarelloAuthor Commented:
Yes..Done !! passing a array instead of ("param1","param2")

        $(document).ready(function () {
            var mylist = new Array();
            mylist.push("michel");
            mylist.push("mortarello");
            mylist.push("costa");

            var obj = CreateObj(mylist);
        });
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now