Question

i have a function and i want to return the Event-id and End-Time but on console.log it returns undefined here is my code:

function Get_Event_Id() {

    return
    {
        EventId: 3
        EndTime: '2014-04-24T11:00:00'
    }
}

var test = GetEventId();
console.log(test);
Was it helpful?

Solution

You can return an object.

var Get_Event_Id = function() {     
    return {
        EventId: 3,
        EndTime: '2014-04-24T11:00:00'
    }
};
var test = Get_Event_Id();
console.log(test.EventId);

http://jsfiddle.net/8LcYr/

OTHER TIPS

The problem is your object is on a new line, that won't work, and the function names must be the same, and you're missing a comma after 3

do this

function GetEventId() {

    return {
        EventId: 3,
        EndTime: '2014-04-24T11:00:00'
    }
}

var test = GetEventId();
console.log(test);

Next time before turning to Stack Overflow as your first and only option go to http://jsfiddle.net and paste your code in the Javascript box, then click on JSLint in the top bar and it will tell you any syntax errors you have

You can return an array instead:

function Get_Event_Id() {  
    var EventId = '3'; // Linked ICDs  
    var EndTime = '2014-04-24T11:00:00';
    return [EventId, EndTime];  
};

var test = Get_Event_Id();
console.log(test); // ["3", "2014-04-24T11:00:00"]

Fiddle Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top