Create Object runtime in javaScript

Posted on 2011-10-17
Last Modified: 2013-11-20
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 = {};
            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");
Question by:Mortarello
    LVL 40

    Accepted Solution

    try replacing this line
       var t =  ".param" + v.toString();
       newobj[t] = args[v];

    by this

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


    Author Comment

    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..


    Author Comment

    Yes..Done !! passing a array instead of ("param1","param2")

            $(document).ready(function () {
                var mylist = new Array();

                var obj = CreateObj(mylist);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    Suggested Solutions

    Title # Comments Views Activity
    Input sanitization for text field 3 26
    DataTables-Form Input column not sorting 7 42
    c# string 6 27
    Table append 4 11
    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now