Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:26:16+00:00 2026-06-18T10:26:16+00:00

If I create a class SONG() , and define many properties, how can i

  • 0

If I create a class SONG(), and define many properties, how can i create a method that will use an argument passed through and get that property?

function SONG(i) {

    /* properties */
    this.title      = results.title[i];
    this.artist     = results.artist[i];
    this.album      = results.album[i];
    this.info       = results.info[i];

    /* methods */
    this.getstuff = function(stuff){
        console.log(this.stuff); // doesn't work
    }
}

var song1 = new SONG(1);

song1.getstuff(title);  
// how can I have this dynamically 'get' the property passed through as an argument?

any help or advice is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:26:17+00:00Added an answer on June 18, 2026 at 10:26 am

    Maybe this is what you want: (JSFiddle)

    function SONG(i) {
        /* properties */
        this.title      = "My Title";
        this.artist     = "My Artist";
        /* methods */
        this.getstuff = function(stuff){
            if (this.hasOwnProperty(stuff))
                return this[stuff];
            else
                return null;
        }
    }
    
    var song1 = new SONG(1);
    
    console.log(song1.getstuff("title"));  
    console.log(song1.getstuff("invalid"));  
    

    But notice here that we are passing in "title" as a string. Also, there needs to be a check within getstuff to validate that SONG indeed has the property that is being requested, hence the check for hasOwnProperty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a class that will store a unique object elements. I
I am trying to create class properties for each element in an array. The
I need to create class Dog and PurebredDog extending Dog. Problem is that Dog
I need to create a class with two properties: LogOutput ExceptionOutput These properties (Actions<>)
I want to create a class for storing attributes of the many data files
I want to create a class which is derived from QLineEdit ,but I can
I want to use SoundPool class to create Playback speed effects. To play sound
A Video , a Song and an Article can have many Tags . And
I'm attempting to create a new Playlist , using Android's ContentResolver , that will
In my app: A song has many setlists through allocations A setlist has many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.