-4

i need to return this.

GetBooking = function (parameter) {
    return Booking.Title[0].parameter;
 }

GetPages = function () {
    return GetBooking(pages) 
 }

GetNumber = function () {
    return GetBooking(number) 
 }

booking is a object of arrays, is possible?

  • 3
    This is an... odd paradigm, and a more odd naming scheme. I would re-consider this design entirely, otherwise you're arbitrarily making things very hard for yourself and future maintainers of this code. – esqew Oct 24 '19 at 14:43
  • 1
    It's a bit unclear. But, you probably need [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation) instead of [dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#Dot_notation) here: `Booking.Title[0][parameter]` – adiga Oct 24 '19 at 15:03

1 Answers1

1

If I understand correctly, when doing GetBooking(pages) you expect to get in return Booking.Title[0].pages, meaning GetBooking() function is supposed to be like a middleman to decide which property you want to get from Booking.Title[0].

If I'm correct, then you almost had it right. What will happen in your code is, for example if number was 7, it would look for a property named 7 inside Booking.Title[0].

What you really want to do is this: return Booking.Title[0][parameter], and parameter has to be a string value representing the property you're looking for, meaning you also need to change the rest of the code which would ultimately look like this:

GetBooking = function (parameter) {
    return Booking.Title[0][parameter];
 }

GetPages = function () {
    return GetBooking("pages") ;
 }

GetNumber = function () {
    return GetBooking("number") ;
 }

This will take the string in parameter and look for a property that matches that string inside Booking.Title[0], and return its value.

Gibor
  • 1,695
  • 6
  • 20