How to resolve TypeError: Cannot convert undefined or null to object

后端 未结 9 1214
生来不讨喜
生来不讨喜 2020-11-28 05:44

I\'ve written a couple of functions that effectively replicate JSON.stringify(), converting a range of values into stringified versions. When I port my code over to JSBin an

相关标签:
9条回答
  • 2020-11-28 06:22

    In my case, I added Lucid extension to Chrome and didn't notice the problem at that moment. After about a day of working on the problem and turning the program upside down, in a post someone had mentioned Lucid. I remembered what I had done and removed the extension from Chrome and ran the program again. The problem was gone. I am working with React. I thought this might help.

    0 讨论(0)
  • 2020-11-28 06:26

    I solved the same problem in a React Native project. I solved it using this.

    let data = snapshot.val();
    if(data){
      let items = Object.values(data);
    }
    else{
      //return null
    }
    
    0 讨论(0)
  • 2020-11-28 06:28

    Replace

    if (typeof obj === 'undefined') { return undefined;} // return undefined for undefined
    if (obj === 'null') { return null;} // null unchanged
    

    with

    if (obj === undefined) { return undefined;} // return undefined for undefined 
    if (obj === null) { return null;} // null unchanged
    
    0 讨论(0)
  • 2020-11-28 06:32

    If you're using Laravel, my problem was in the name of my Route. Instead:

    Route::put('/reason/update', 'REASONController@update');
    

    I wrote:

    Route::put('/reason/update', 'RESONController@update');
    

    and when I fixed the controller name, the code worked!

    0 讨论(0)
  • 2020-11-28 06:33

    I have the same problem with a element in a webform. So what I did to fix it was validate. if(Object === 'null') do something

    0 讨论(0)
  • 2020-11-28 06:35

    In my case I had an extra pair of parenthesis ()

    Instead of

    export default connect(
      someVariable
    )(otherVariable)()
    

    It had to be

    export default connect(
      someVariable
    )(otherVariable)
    
    0 讨论(0)
提交回复
热议问题